40
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Logging macros used by DS plug-in adapters
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#ifndef __LOGGER_H__
|
|
20 |
#define __LOGGER_H__
|
|
21 |
|
|
22 |
#ifdef _DEBUG
|
|
23 |
|
|
24 |
// Define this to enable file logging
|
|
25 |
#define __FLOGGING__
|
|
26 |
|
|
27 |
#include <f32file.h>
|
|
28 |
#include <flogger.h>
|
|
29 |
#include <e32std.h>
|
|
30 |
#include <e32def.h>
|
|
31 |
|
|
32 |
NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow
|
|
33 |
{
|
|
34 |
public:
|
|
35 |
void Overflow(TDes16& /*aDes*/) {}
|
|
36 |
};
|
|
37 |
|
|
38 |
NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
|
|
39 |
{
|
|
40 |
public:
|
|
41 |
void Overflow(TDes8& /*aDes*/) {}
|
|
42 |
};
|
|
43 |
|
|
44 |
_LIT(KLogDir, "SMS");
|
|
45 |
_LIT(KLogFile, "SMSDataproviderLog.txt");
|
|
46 |
_LIT( KLogFormat, "[SMSDS] %S");
|
|
47 |
|
|
48 |
|
|
49 |
_LIT(KTracePrefix16, "[SMSDS] ");
|
|
50 |
_LIT8(KTracePrefix8, "[SMSDS] ");
|
|
51 |
_LIT8(KFuncEntryFormat8, "%S : Begin");
|
|
52 |
_LIT8(KFuncExitFormat8, "%S : End");
|
|
53 |
_LIT8(KFuncFormat8, "><%S");
|
|
54 |
|
|
55 |
const TInt KMaxLogLineLength = 512;
|
|
56 |
|
|
57 |
/**
|
|
58 |
* Old logging macros
|
|
59 |
*/
|
|
60 |
#ifdef __FLOGGING__
|
|
61 |
#define LOG( AAA ) RFileLogger::Write( KLogDir,KLogFile,EFileLoggingModeAppend,AAA )
|
|
62 |
#else
|
|
63 |
#define LOG( AAA )
|
|
64 |
#endif
|
|
65 |
#define LOG2( text, par1 ) { FPrint( text, par1 ); }
|
|
66 |
|
|
67 |
|
|
68 |
// old function loggin macros
|
|
69 |
#define LOGGER_ENTERFN( name ) {TRACE_FUNC_ENTRY;}
|
|
70 |
#define LOGGER_LEAVEFN( name ) {TRACE_FUNC_EXIT;}
|
|
71 |
|
|
72 |
#define LOGGER_WRITE( text ) {_LIT( KTemp, text ); FPrint( KTemp );}
|
|
73 |
#define LOGGER_WRITE_1( text,par1 ) {_LIT( KTemp, text ); FPrint( KTemp, par1 );}
|
|
74 |
#define LOGGER_WRITE_2( text,par1,par2 ) {_LIT( KTemp, text ); FPrint( KTemp, par1, par2 );}
|
|
75 |
|
|
76 |
// New function logging macros
|
|
77 |
#define TRACE_FUNC_ENTRY {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncEntryFormat8, &ptr8);}
|
|
78 |
#define TRACE_FUNC_EXIT {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncExitFormat8, &ptr8);}
|
|
79 |
#define TRACE_FUNC {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncFormat8, &ptr8);}
|
|
80 |
|
|
81 |
|
|
82 |
// Declare the FPrint function
|
|
83 |
inline void FPrint( TRefByValue<const TDesC16> aFmt, ...)
|
|
84 |
{
|
|
85 |
VA_LIST list;
|
|
86 |
VA_START(list,aFmt);
|
|
87 |
#if defined ( __FLOGGING__ )
|
|
88 |
RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
|
|
89 |
#endif
|
|
90 |
|
|
91 |
TBuf16<KMaxLogLineLength> theFinalString;
|
|
92 |
theFinalString.Append(KTracePrefix16);
|
|
93 |
TOverflowTruncate16 overflow;
|
|
94 |
theFinalString.AppendFormatList(aFmt,list,&overflow);
|
|
95 |
RDebug::Print(theFinalString);
|
|
96 |
}
|
|
97 |
|
|
98 |
inline void FPrint(TRefByValue<const TDesC8> aFmt, ...)
|
|
99 |
{
|
|
100 |
VA_LIST list;
|
|
101 |
VA_START(list, aFmt);
|
|
102 |
#ifdef __FLOGGING__
|
|
103 |
RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
|
|
104 |
#endif
|
|
105 |
TOverflowTruncate8 overflow;
|
|
106 |
TBuf8<KMaxLogLineLength> buf8;
|
|
107 |
buf8.Append(KTracePrefix8);
|
|
108 |
buf8.AppendFormatList(aFmt, list, &overflow);
|
|
109 |
TBuf16<KMaxLogLineLength> buf16(buf8.Length());
|
|
110 |
buf16.Copy(buf8);
|
|
111 |
TRefByValue<const TDesC> tmpFmt(_L("%S"));
|
|
112 |
RDebug::Print(tmpFmt, &buf16);
|
|
113 |
}
|
|
114 |
#else // no _DEBUG defined
|
|
115 |
|
|
116 |
#define LOG( A )
|
|
117 |
#define LOG2( A, B )
|
|
118 |
|
|
119 |
#define LOGGER_ENTERFN( name )
|
|
120 |
#define LOGGER_LEAVEFN( name )
|
|
121 |
#define LOGGER_WRITE( text )
|
|
122 |
#define LOGGER_WRITE_1( text,par1 )
|
|
123 |
#define LOGGER_WRITE_2( text,par1,par2 )
|
|
124 |
|
|
125 |
#define TRACE_FUNC_ENTRY
|
|
126 |
#define TRACE_FUNC_EXIT
|
|
127 |
#define TRACE_FUNC
|
|
128 |
|
|
129 |
|
|
130 |
#endif // _DEBUG
|
|
131 |
|
|
132 |
#endif // __LOGGER_H__
|
|
133 |
|