os/persistentdata/traceservices/tracefw/common_utils/lightlogger/inc/lightlogger.h
Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
23 #ifndef LIGHTLOGGER_H_
24 #define LIGHTLOGGER_H_
32 #include <hal.h> //if you are going to use __HIRES_RESOLUTION or __GET_Resolution
33 //use "hal.lib" in your project
36 //<LightLogger output file>
38 _LIT(KLogFile,"c:\\light_log.txt");
40 _LIT(KLogFile,"e:\\light_log.txt");
42 //</LightLogger output file>
46 _LIT8(KLLNewLine, "\n");
52 * Record id decribes type of LightLogger record and can be used by external tools to manage logs views
53 * or automate timestamp calculations.
55 const int gLL_MachineResolutionId = 0;
56 const int gLL_TimestampHiResId = 1;
57 const int gLL_TimestampLoResId = 2;
61 #if defined __LIGHTLOGGER_ENABLED
62 //This code must be called before other macros. It just create fresh log file.
64 if you want to reset file use: __CREATE_LOG(true), otherwise __CREATE_LOG(false)
66 #define __CREATE_LOG(replace) {TBool r(replace);RFs fs;RFile f;fs.Connect();\
67 if(r){f.Replace(fs, KLogFile, EFileWrite);}else{\
68 if(f.Open(fs, KLogFile, EFileWrite)==KErrNotFound){\
69 f.Replace(fs, KLogFile, EFileWrite);}\
70 }f.Close(); fs.Close();}
72 //Log text object to file
73 //example: __LOG("ty text")
74 #define __LOG(x) {TBuf8<512> b;RFs fs;RFile f;b.Zero(); b.Copy(_L(x)); b.Append(KLLNewLine); fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){TInt s; f.Size(s); f.Seek(ESeekStart,s); f.Write(b); f.Close();} fs.Close();}
76 //Log number object to file.
77 //exaple: TInt i=4; __LOG(i);
78 #define __LOGNUM(x) {TBuf8<256> b;RFs fs;RFile f;b.Zero(); b.Num(x);b.Append(KLLNewLine); fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){TInt s; f.Size(s); f.Seek(ESeekStart,s); f.Write(b); f.Close();} fs.Close();}
84 * b.Append(_L("some text"));
87 #define __LOGBUF(x) {TBuf8<512> b;RFs fs;RFile f;b.Copy(x);b.Append(KLLNewLine); fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); f.Write(b); f.Close();} fs.Close();}
89 //Log timestamp (low resolution) with additional text object to file .
90 //Time stamp format: hour:minute:second:microsecond - user text comment
91 #define __LOGTIMESTAMP(x) {TTime time; time.HomeTime(); TBuf8<256> b; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); \
92 TDateTime dt = time.DateTime();\
93 b.AppendFormat(_L8("<[%d]> <[%d:%d:%d:%d]> %S"), gLL_TimestampLoResId, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond(), &_L8(x)); b.Append(KLLNewLine);\
95 f.Close();} fs.Close();\
98 //Log tick count to file.
99 #define __LOGTICKCOUNT {_LIT8(KTick,"TickCount: %u"); TBuf8<256> b; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); \
100 b.AppendFormat(KTick, User::TickCount()); b.Append(KLLNewLine); f.Write(b); f.Close();} fs.Close();\
103 //Log high resolution time stamp to file with additional user comment.
105 This is the current value of the machine's high resolution timer.
106 If a high resolution timer is not available, it uses the millisecond timer instead.
108 #define __LOGTIMESTAMP_HIRES(x){TBuf8<256> b; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){ TInt s; f.Size(s); f.Seek(ESeekStart,s); \
109 b.AppendFormat(_L8("<[%d]> <[%u]> %S"), gLL_TimestampHiResId, __GET_HiResTimestamp(), &_L8(x)); b.Append(KLLNewLine);\
111 f.Close();} fs.Close();\
114 //Fast counter resolution
116 #define __HIRES_RESOLUTION { TInt _tmp_=gLL_MachineResolutionId; RFs fs; RFile f; fs.Connect(); if(f.Open(fs, KLogFile, EFileWrite)==KErrNone){TInt s;f.Size(s);f.Seek(ESeekStart,s); \
117 TBuf8<256> b;b.AppendFormat(_L8("<[%d]> <[%d]> Fast timer resolution"), _tmp_, __GET_Resolution());b.Append(KLLNewLine);f.Write(b); f.Close();} fs.Close();\
120 /**This function returns resolution of fast counter
123 inline TUint32 __GET_Resolution()
126 HAL::Get(HALData::EFastCounterFrequency, freq);
130 /**This function returns hi resolution counter (timestamp)
133 inline TUint32 __GET_HiResTimestamp() {return User::FastCounter();}
136 /**Method marker class
142 TMethodMarker(const TDesC8& aMethod)
153 /**This macro is logging entry and exit points from method specified as parameter.
155 #define __MARK_METHOD(x) TBuf8<128> b; b.AppendFormat(_L8("%S\n{"), &_L8(x)); TMethodMarker m(b);
160 #define __CREATE_LOG(replace)
164 #define __LOGTIMESTAMP(x)
165 #define __LOGTICKCOUNT
166 #define __LOGTIMESTAMP_HIRES(x)
167 #define __HIRES_RESOLUTION
168 inline TUint32 __GET_Resolution(){return 0;}
169 inline TUint32 __GET_HiResTimestamp(){return 0;}
170 #define __MARK_METHOD(x)
172 #endif //__LIGHLOGGER_ENABLED
173 #endif /*LIGHTLOGGER_H_*/
178 * Special data format for certain macros (__HIRES_RESOLUTION; __LOGTIMESTAMP; __LOGTIMESTAMP_HIRES):
179 * "<[record_id]> <[value]> description>"
181 * record_id - is an integer value
182 * value - is an integer value
183 * description - is a string value