|
1 /* |
|
2 * Copyright (c) 2004-2008 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: Printing log messages |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #if !defined(__LOGCOMMON_H__) |
|
21 #define __LOGCOMMON_H__ |
|
22 |
|
23 #if !defined(_DEBUG) |
|
24 |
|
25 #define LOG(a) |
|
26 #define LOG_(a) |
|
27 #define LOG_1(s, v) |
|
28 #define LOG8_(a) |
|
29 #define LOG8_1(s, v) |
|
30 #define STACK_LEFT |
|
31 |
|
32 #else // _DEBUG |
|
33 |
|
34 #define LOG(a) a |
|
35 #define LOG_(a) Log::Printf( _L(a) ) |
|
36 #define LOG_1(s, v) Log::Printf( _L(s), v ) |
|
37 #define LOG8_(a) Log::Printf( _L8(a) ) |
|
38 #define LOG8_1(s, v) Log::Printf( _L8(s), v ) |
|
39 #define STACK_LEFT { RThread __r; TThreadStackInfo __i; __r.StackInfo(__i); TInt maxSize = __i.iBase - __i.iLimit; TInt currentSize = __i.iBase - (TInt)&__r; Log::Printf( _L("Max stack size: %d, current size: %d"), maxSize, currentSize); } |
|
40 |
|
41 #include <flogger.h> |
|
42 _LIT(KLogFolder,"vpn"); |
|
43 |
|
44 class Log |
|
45 { |
|
46 public: |
|
47 static inline void Write(const TDesC16& aDes); |
|
48 static inline void Write(const TDesC8& aDes); |
|
49 static inline void Printf(TRefByValue<const TDesC> aFmt, ...); |
|
50 static inline void Printf(TRefByValue<const TDesC8> aFmt, ...); |
|
51 static inline void HexDump(const TText* aHeader, const TText* aMargin, const TUint8* aPtr, TInt aLen); |
|
52 }; |
|
53 |
|
54 inline void Log::Write(const TDesC16& aDes) |
|
55 { |
|
56 RFileLogger logger; |
|
57 if (logger.Connect() != KErrNone) |
|
58 return; |
|
59 logger.CreateLog(KLogFolder(), KLogFile(), EFileLoggingModeAppend); |
|
60 TInt maxLen = (KLogBufferSize < 100) ? KLogBufferSize : 100; |
|
61 TInt start(0); |
|
62 while (start < aDes.Length()) |
|
63 { |
|
64 TInt length = (start + maxLen >= aDes.Length()) ? |
|
65 (aDes.Length() - start) : maxLen; |
|
66 TInt addLength = length; |
|
67 const TDesC16 &tmp = aDes.Mid(start, length); |
|
68 |
|
69 TInt linefeedPos = tmp.Find(_L("\n")); |
|
70 if (linefeedPos != KErrNotFound) |
|
71 { |
|
72 length -= (length - linefeedPos); |
|
73 addLength = length + 1; // To skip linefeed |
|
74 } |
|
75 |
|
76 logger.Write(tmp.Left(length)); |
|
77 start += addLength; |
|
78 } |
|
79 logger.Close(); |
|
80 } |
|
81 |
|
82 inline void Log::Write(const TDesC8& aDes) |
|
83 { |
|
84 RFileLogger logger; |
|
85 if (logger.Connect() != KErrNone) |
|
86 return; |
|
87 logger.CreateLog(KLogFolder(), KLogFile(), EFileLoggingModeAppend); |
|
88 TInt maxLen = (KLogBufferSize < 100) ? KLogBufferSize : 100; |
|
89 TInt start(0); |
|
90 while (start < aDes.Length()) |
|
91 { |
|
92 TInt length = (start + maxLen >= aDes.Length()) ? |
|
93 (aDes.Length() - start) : maxLen; |
|
94 TInt addLength = length; |
|
95 const TDesC8 &tmp = aDes.Mid(start, length); |
|
96 |
|
97 TInt linefeedPos = tmp.Find(_L8("\n")); |
|
98 if (linefeedPos != KErrNotFound) |
|
99 { |
|
100 length -= (length - linefeedPos); |
|
101 addLength = length + 1; // To skip linefeed |
|
102 } |
|
103 |
|
104 logger.Write(tmp.Left(length)); |
|
105 start += addLength; |
|
106 } |
|
107 logger.Close(); |
|
108 } |
|
109 |
|
110 inline void Log::Printf(TRefByValue<const TDesC> aFmt, ...) |
|
111 { |
|
112 VA_LIST list; |
|
113 VA_START(list,aFmt); |
|
114 const TInt KLogTimeFormatLength = 16; |
|
115 const TInt KLogLineLength = 256; |
|
116 TBuf<KLogLineLength> buf; |
|
117 buf.FormatList( aFmt, list ); |
|
118 |
|
119 RFileLogger logger; |
|
120 TInt ret = logger.Connect(); |
|
121 if (ret==KErrNone) |
|
122 { |
|
123 _LIT( KLogTimeFormat, "%02d:%02d,%02d,%06d;"); |
|
124 logger.SetDateAndTime( ETrue, EFalse ); |
|
125 logger.CreateLog( KLogFolder(), KLogFile(), EFileLoggingModeAppend ); |
|
126 TBuf<KLogTimeFormatLength> timeStamp; |
|
127 TTime now; |
|
128 now.HomeTime(); |
|
129 TDateTime dateTime; |
|
130 dateTime = now.DateTime(); |
|
131 timeStamp.Format( KLogTimeFormat, |
|
132 dateTime.Hour(), dateTime.Minute(), dateTime.Second(), dateTime.MicroSecond() ); |
|
133 buf.Insert( 0, timeStamp ); |
|
134 |
|
135 logger.Write(buf); |
|
136 } |
|
137 |
|
138 logger.Close(); |
|
139 |
|
140 //RFileLogger::WriteFormat(KLogFolder(), KLogFile(), EFileLoggingModeAppend, aFmt, list); |
|
141 } |
|
142 |
|
143 inline void Log::Printf(TRefByValue<const TDesC8> aFmt, ...) |
|
144 { |
|
145 VA_LIST list; |
|
146 VA_START(list,aFmt); |
|
147 RFileLogger::WriteFormat(KLogFolder(), KLogFile(), EFileLoggingModeAppend, aFmt, list); |
|
148 } |
|
149 |
|
150 inline void Log::HexDump(const TText* aHeader, const TText* aMargin, const TUint8* aPtr, TInt aLen) |
|
151 { |
|
152 RFileLogger::HexDump(KLogFolder(), KLogFile(), EFileLoggingModeAppend, aHeader, aMargin, aPtr, aLen); |
|
153 } |
|
154 |
|
155 |
|
156 #endif // !defined(_DEBUG) |
|
157 |
|
158 #endif //__LOGCOMMON_H__ |