|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * Logging macros for MsgMedia.dll |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // ========== LOGGING MACROS =============================== |
|
22 |
|
23 #ifndef __MSGMEDIALOGGING_H |
|
24 #define __MSGMEDIALOGGING_H |
|
25 |
|
26 #ifdef __MSGMEDIA_DEBUG |
|
27 |
|
28 #include <e32std.h> |
|
29 #include <e32def.h> |
|
30 #include <flogger.h> |
|
31 |
|
32 /* logging macros usage: |
|
33 |
|
34 // replace MSGM with your own TLA (Three Letter Acronyme). |
|
35 |
|
36 // set logging on in mmp file... |
|
37 MACRO __MSGMEDIA_DEBUG |
|
38 #ifdef WINS |
|
39 MACRO USE_RDEBUG |
|
40 #endif |
|
41 |
|
42 |
|
43 void CTestAppUi::ConstructL() |
|
44 { |
|
45 // creates log directory and log file on app startup. |
|
46 // prints starting banner... |
|
47 MSGMLOGGER_CREATE(iFs); |
|
48 |
|
49 // entering to function... |
|
50 MSGMLOGGER_ENTERFN("ConstructL()"); |
|
51 |
|
52 TInt number = 42; |
|
53 TFileName file; |
|
54 file = "something" .... |
|
55 |
|
56 // print variable number of parameters... |
|
57 // Note: use _L macro for format string! |
|
58 MSGMLOGGER_WRITEF(_L("MSGM: number = %d, file = %S"), number, &file); |
|
59 |
|
60 // print just a string (no _L macro here!) |
|
61 MSGMLOGGER_WRITE("Hello world!"); |
|
62 |
|
63 // leave from function... |
|
64 MSGMLOGGER_LEAVEFN("ConstructL()"); |
|
65 } |
|
66 |
|
67 CTestAppUi::~CTestAppUi() |
|
68 { |
|
69 // print app exit banner when application exits. |
|
70 MSGMLOGGER_DELETE; |
|
71 } |
|
72 |
|
73 */ |
|
74 |
|
75 #ifdef USE_RDEBUG |
|
76 |
|
77 _LIT(KMSGMLogBanner, "MSGM - MsgMedia"); |
|
78 _LIT(KMSGMLogEnterFn, "MSGM: >> %S"); |
|
79 _LIT(KMSGMLogLeaveFn, "MSGM: << %S"); |
|
80 _LIT(KMSGMLogWrite, "MSGM: %S"); |
|
81 _LIT(KMSGMLogTag, "MSGM: "); |
|
82 _LIT(KMSGMLogExit, "MSGM: Application exit"); |
|
83 _LIT(KMSGMLogTimeFormatString, "%H:%T:%S:%*C2"); |
|
84 |
|
85 #define MSGMLOGGER_CREATE(a) {RDebug::Print(KMSGMLogBanner);} |
|
86 #define MSGMLOGGER_DELETE {RDebug::Print(KMSGMLogExit);} |
|
87 #define MSGMLOGGER_ENTERFN(a) {_LIT(temp, a); RDebug::Print(KMSGMLogEnterFn, &temp);} |
|
88 #define MSGMLOGGER_LEAVEFN(a) {_LIT(temp, a); RDebug::Print(KMSGMLogLeaveFn, &temp);} |
|
89 #define MSGMLOGGER_WRITE(a) {_LIT(temp, a); RDebug::Print(KMSGMLogWrite, &temp);} |
|
90 #define MSGMLOGGER_WRITE_TIMESTAMP(a) {_LIT(temp, a); TTime time; time.HomeTime(); TBuf<256> buffer; time.FormatL( buffer, KMSGMLogTimeFormatString ); buffer.Insert(0, temp); buffer.Insert(0, KMSGMLogTag); RDebug::Print(buffer); } |
|
91 #define MSGMLOGGER_WRITEF RDebug::Print |
|
92 |
|
93 #else |
|
94 |
|
95 _LIT( KMSGMLogDir, "MSGM"); |
|
96 _LIT( KMSGMLogFile, "MSGM.txt"); |
|
97 _LIT8(KMSGMLogBanner, "MSGM - MsgMedia"); |
|
98 _LIT8(KMSGMLogEnterFn, "MSGM: >> %S"); |
|
99 _LIT8(KMSGMLogLeaveFn, "MSGM: << %S"); |
|
100 _LIT8(KMSGMLogExit, "MSGM: Application exit"); |
|
101 _LIT( KMSGMLogTimeFormatString, "%H:%T:%S:%*C2"); |
|
102 |
|
103 #define MSGMLOGGER_CREATE(a) {MSGM_FCreate(a);} |
|
104 #define MSGMLOGGER_DELETE {RFileLogger::Write(KMSGMLogDir, KMSGMLogFile, EFileLoggingModeAppend, KMSGMLogExit);} |
|
105 #define MSGMLOGGER_ENTERFN(a) {_LIT8(temp, a); RFileLogger::WriteFormat(KMSGMLogDir, KMSGMLogFile, EFileLoggingModeAppend, KMSGMLogEnterFn, &temp);} |
|
106 #define MSGMLOGGER_LEAVEFN(a) {_LIT8(temp, a); RFileLogger::WriteFormat(KMSGMLogDir, KMSGMLogFile, EFileLoggingModeAppend, KMSGMLogLeaveFn, &temp);} |
|
107 #define MSGMLOGGER_WRITE(a) {_LIT(temp, a); RFileLogger::Write(KMSGMLogDir, KMSGMLogFile, EFileLoggingModeAppend, temp);} |
|
108 #define MSGMLOGGER_WRITE_TIMESTAMP(a) {_LIT(temp, a); TTime time; time.HomeTime(); TBuf<256> buffer; time.FormatL( buffer, KMSGMLogTimeFormatString ); buffer.Insert(0, temp); RFileLogger::Write(KMSGMLogDir, KMSGMLogFile, EFileLoggingModeAppend, buffer); } |
|
109 #define MSGMLOGGER_WRITEF MSGM_FPrint |
|
110 |
|
111 inline void MSGM_FPrint(const TRefByValue<const TDesC> aFmt, ...) |
|
112 { |
|
113 VA_LIST list; |
|
114 VA_START(list,aFmt); |
|
115 RFileLogger::WriteFormat(KMSGMLogDir, KMSGMLogFile, EFileLoggingModeAppend, aFmt, list); |
|
116 } |
|
117 |
|
118 inline void MSGM_FPrint(const TDesC& aDes) |
|
119 { |
|
120 RFileLogger::WriteFormat(KMSGMLogDir, KMSGMLogFile, EFileLoggingModeAppend, aDes); |
|
121 } |
|
122 |
|
123 inline void MSGM_FHex(const TUint8* aPtr, TInt aLen) |
|
124 { |
|
125 RFileLogger::HexDump(KMSGMLogDir, KMSGMLogFile, EFileLoggingModeAppend, 0, 0, aPtr, aLen); |
|
126 } |
|
127 |
|
128 inline void MSGM_FHex(const TDesC8& aDes) |
|
129 { |
|
130 MSGM_FHex(aDes.Ptr(), aDes.Length()); |
|
131 } |
|
132 |
|
133 inline void MSGM_FCreate(RFs& aFs) |
|
134 { |
|
135 TFileName path(_L("c:\\logs\\")); |
|
136 path.Append(KMSGMLogDir); |
|
137 path.Append(_L("\\")); |
|
138 aFs.MkDirAll(path); |
|
139 RFileLogger::WriteFormat(KMSGMLogDir, KMSGMLogFile, EFileLoggingModeOverwrite, KMSGMLogBanner); |
|
140 } |
|
141 |
|
142 #endif // USE_RDEBUG |
|
143 |
|
144 #else // __MSGMEDIA_DEBUG |
|
145 |
|
146 // dummy inline MSGM_FPrint for MSGMLOGGER_WRITEF macro. |
|
147 inline TInt MSGM_FPrint(const TRefByValue<const TDesC> /*aFmt*/, ...) { return 0; } |
|
148 |
|
149 #define MSGMLOGGER_CREATE(a) |
|
150 #define MSGMLOGGER_DELETE |
|
151 #define MSGMLOGGER_ENTERFN(a) |
|
152 #define MSGMLOGGER_LEAVEFN(a) |
|
153 #define MSGMLOGGER_WRITE(a) |
|
154 // if __MSGMEDIA_DEBUG not defined this call to FPrint gets optimized away. |
|
155 #define MSGMLOGGER_WRITEF 1 ? 0 : MSGM_FPrint |
|
156 #define MSGMLOGGER_WRITE_TIMESTAMP(a) |
|
157 |
|
158 #endif // __MSGMEDIA_DEBUG |
|
159 |
|
160 #endif // __MSGMEDIALOGGING_H |
|
161 |
|
162 // ========================================================= |