|
1 /* |
|
2 * Copyright (c) 2004-2007 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32svr.h> |
|
20 |
|
21 #include "clog.h" |
|
22 |
|
23 #ifdef ENABLE_LOGGING |
|
24 |
|
25 #ifdef LOG_TO_FILE |
|
26 |
|
27 #include <flogger.h> |
|
28 /// Folder where the log resides |
|
29 _LIT( KLogFolder, "ip_log" ); |
|
30 /// The name of the log file |
|
31 _LIT( KLogFileName, "imageprintlog.txt" ); |
|
32 /// The format in which the time is formatted in log |
|
33 _LIT( KLogTimeFormat, "%02d.%02d:%02d:%06d "); |
|
34 _LIT8( KLogTimeFormat8, "%02d.%02d:%02d:%06d "); |
|
35 /// The length of the string produced by KLogTimeFormat |
|
36 const TInt KLogTimeFormatLength = 16; |
|
37 |
|
38 #endif // LOG_TO_FILE |
|
39 |
|
40 /// How many characters a log line can contain |
|
41 const TInt KLogLineLength = 256; |
|
42 |
|
43 #endif // ENABLE_LOGGING |
|
44 |
|
45 #ifdef ENABLE_LOGGING |
|
46 |
|
47 void Log::DoLog( TRefByValue<const TDesC> aText, ... ) |
|
48 { |
|
49 VA_LIST args; |
|
50 VA_START( args, aText ); |
|
51 |
|
52 TBuf<KLogLineLength> buf; |
|
53 buf.FormatList( aText, args ); |
|
54 |
|
55 #ifdef LOG_TO_FILE |
|
56 RFileLogger logger; |
|
57 TInt ret = logger.Connect(); |
|
58 if (ret==KErrNone) |
|
59 { |
|
60 logger.SetDateAndTime( EFalse,EFalse ); |
|
61 logger.CreateLog( KLogFolder, KLogFileName, EFileLoggingModeAppend ); |
|
62 TBuf<KLogTimeFormatLength> timeStamp; |
|
63 TTime now; |
|
64 now.HomeTime(); |
|
65 TDateTime dateTime; |
|
66 dateTime = now.DateTime(); |
|
67 timeStamp.Format( KLogTimeFormat, |
|
68 dateTime.Hour(), dateTime.Minute(), |
|
69 dateTime.Second(), dateTime.MicroSecond() ); |
|
70 buf.Insert( 0, timeStamp ); |
|
71 |
|
72 logger.Write(buf); |
|
73 } |
|
74 |
|
75 logger.Close(); |
|
76 #else |
|
77 RDebug::Print( buf ); |
|
78 #endif // LOG_TO_FILE |
|
79 VA_END( args ); |
|
80 } |
|
81 |
|
82 void Log::DoLog8( TRefByValue<const TDesC8> aText, ... ) |
|
83 { |
|
84 VA_LIST args; |
|
85 VA_START( args, aText ); |
|
86 |
|
87 TBuf8<KLogLineLength> buf; |
|
88 buf.FormatList( aText, args ); |
|
89 #ifdef LOG_TO_FILE |
|
90 RFileLogger logger; |
|
91 TInt ret = logger.Connect(); |
|
92 if (ret==KErrNone) |
|
93 { |
|
94 logger.SetDateAndTime( EFalse,EFalse ); |
|
95 logger.CreateLog( KLogFolder, KLogFileName, EFileLoggingModeAppend ); |
|
96 TBuf8<KLogTimeFormatLength> timeStamp; |
|
97 TTime now; |
|
98 now.HomeTime(); |
|
99 TDateTime dateTime; |
|
100 dateTime = now.DateTime(); |
|
101 timeStamp.Format( KLogTimeFormat8, |
|
102 dateTime.Hour(), dateTime.Minute(), |
|
103 dateTime.Second(), dateTime.MicroSecond() ); |
|
104 buf.Insert( 0, timeStamp ); |
|
105 |
|
106 logger.Write(buf); |
|
107 } |
|
108 |
|
109 logger.Close(); |
|
110 #else |
|
111 TBuf<KLogLineLength> buf16; |
|
112 buf16.Copy(buf); |
|
113 RDebug::Print( buf16 ); |
|
114 #endif // LOG_TO_FILE |
|
115 VA_END( args ); |
|
116 } |
|
117 |
|
118 #endif // ENABLE_LOGGING |
|
119 // End of File |