|
1 /* |
|
2 * Copyright (c) 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef LOG_H |
|
20 #define LOG_H |
|
21 |
|
22 #ifdef _DEBUG |
|
23 #define _LOGGING |
|
24 #endif |
|
25 |
|
26 #ifdef _LOGGING |
|
27 |
|
28 #include <e32std.h> |
|
29 #include <f32file.h> |
|
30 #include <flogger.h> |
|
31 |
|
32 #ifndef _LOGGING_DIR |
|
33 #define _LOGGING_DIR L"wmdrm" |
|
34 #endif |
|
35 |
|
36 #ifndef _LOGGING_FILE |
|
37 #define _LOGGING_FILE L"wmdrm.txt" |
|
38 #endif |
|
39 |
|
40 const static TLitC<sizeof(_LOGGING_DIR) / 2> KLogDir = |
|
41 { |
|
42 sizeof(_LOGGING_DIR) / 2 - 1, _LOGGING_DIR |
|
43 }; |
|
44 const static TLitC<sizeof(_LOGGING_FILE) / 2> KLogFile = |
|
45 { |
|
46 sizeof(_LOGGING_FILE) / 2 - 1, _LOGGING_FILE |
|
47 }; |
|
48 |
|
49 #define LOG( des ) \ |
|
50 RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, des ) |
|
51 |
|
52 #define LOG1( AAA ) \ |
|
53 RFileLogger::Write( KLogDir, KLogFile, EFileLoggingModeAppend, _L( AAA ) ) |
|
54 |
|
55 #define LOG2( FMT, BBB ) \ |
|
56 RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, _L( FMT ), BBB ) |
|
57 |
|
58 #define LOG3( FMT, BBB, CCC ) \ |
|
59 RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, _L( FMT ), BBB, CCC ) |
|
60 |
|
61 #define LOG4( FMT, BBB, CCC, DDD ) \ |
|
62 RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, _L( FMT ), BBB, CCC, DDD ) |
|
63 |
|
64 #define LOG5( FMT, BBB, CCC, DDD, EEE ) \ |
|
65 RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, _L( FMT ), BBB, CCC, DDD, EEE ) |
|
66 |
|
67 #define LOGHEX( ptr, len ) \ |
|
68 RFileLogger::HexDump( KLogDir, KLogFile, EFileLoggingModeAppend, _S(""), _S(""), ptr, len ) |
|
69 |
|
70 #define LOGFN( AAA ) TLogFn ___tmp( _L( AAA ) ) |
|
71 #define LOGFNR( AAA, BBB ) TLogFn ___tmp( _L( AAA ), (TInt* ) &( BBB ) ) |
|
72 |
|
73 #define CLEARLOG() {\ |
|
74 RFs fs;\ |
|
75 TBuf<sizeof( _LOGGING_DIR ) + sizeof( _LOGGING_DIR ) + 32> path;\ |
|
76 path.Copy( _L( "c:\\logs\\" ) ); path.Append( KLogDir ); path.Append( '\\' ); path.Append( KLogFile ); \ |
|
77 fs.Connect();\ |
|
78 fs.Delete( path );\ |
|
79 fs.Close();} |
|
80 |
|
81 /** |
|
82 * Class for logging funtion calls and exits |
|
83 * |
|
84 * The constructor logs the entry of the function, the destructor the exit |
|
85 * |
|
86 * @since S60 3.2 |
|
87 */ |
|
88 NONSHARABLE_CLASS( TLogFn ) |
|
89 { |
|
90 public: |
|
91 TLogFn( const TDesC& aName, TInt* aResult = NULL ): |
|
92 iResult( aResult) |
|
93 { |
|
94 RBuf8 data; |
|
95 |
|
96 iName.Set( aName ); |
|
97 if ( data.Create( iName.Size() + 8 ) == KErrNone ) |
|
98 { |
|
99 data.Copy( _L( ">> " ) ); |
|
100 data.Append( iName ); |
|
101 LOG( data ); |
|
102 data.Close(); |
|
103 } |
|
104 } |
|
105 |
|
106 ~TLogFn() |
|
107 { |
|
108 RBuf8 data; |
|
109 |
|
110 if ( data.Create( iName.Size() + 50 ) == KErrNone ) |
|
111 { |
|
112 data.Copy( _L( "<< " ) ); |
|
113 data.Append( iName ); |
|
114 if ( iResult ) |
|
115 { |
|
116 data.Append( ' ' ); |
|
117 data.AppendNum( *iResult ); |
|
118 data.Append( _L( " 0x" ) ); |
|
119 data.AppendNum( *iResult, EHex ); |
|
120 } |
|
121 LOG( data ); |
|
122 data.Close(); |
|
123 } |
|
124 } |
|
125 |
|
126 private: // data |
|
127 |
|
128 /** |
|
129 * Name of the function |
|
130 */ |
|
131 TPtrC iName; |
|
132 TInt* iResult; |
|
133 }; |
|
134 |
|
135 #else // _LOGGING |
|
136 |
|
137 #define LOG( des ) |
|
138 #define LOG1( AAA ) |
|
139 #define LOG2( FMT, BBB ) |
|
140 #define LOG3( FMT, BBB, CCC ) |
|
141 #define LOG4( FMT, BBB, CCC, DDD ) |
|
142 #define LOG5( FMT, BBB, CCC, DDD, EEE ) |
|
143 #define LOGHEX( ptr, len ) |
|
144 #define LOGFN( AAA ) |
|
145 #define LOGFNR( AAA, BBB ) |
|
146 #define CLEARLOG() |
|
147 |
|
148 #endif // _LOGGING |
|
149 |
|
150 #endif // LOG_H |