|
1 /* |
|
2 * Copyright (c) 2006 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: logger implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "impslogger.h" |
|
20 #include "IMPSConfig.h" |
|
21 #include "impsdebugprint.h" |
|
22 |
|
23 #include <E32Svr.h> |
|
24 #include <E32Std.h> |
|
25 #include <flogger.h> |
|
26 |
|
27 |
|
28 /** |
|
29 * Handler used by logger to truncate the string |
|
30 * rather than panic in case of buffer overflow. |
|
31 * |
|
32 * @since 3.0 |
|
33 */ |
|
34 NONSHARABLE_CLASS( TIMPSOverflowTruncate ) : public TDes16Overflow |
|
35 { |
|
36 public: |
|
37 void Overflow( TDes16& /*aDes*/ ) {} |
|
38 }; |
|
39 |
|
40 |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // ImpsLogger::WriteLog() |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 //EXPORT_C void IMPSLogger::WriteLog( TRefByValue<const TDesC> aFmt,... ) |
|
49 void IMPSLogger::WriteLog( TRefByValue<const TDesC> aFmt, ... ) |
|
50 { |
|
51 //Suppress unused formal parameter warning |
|
52 ( void )aFmt; |
|
53 |
|
54 #ifdef IMPS_ENABLE_DEBUG_PRINT |
|
55 |
|
56 //Format the log line |
|
57 TBuf< KIMPSMaxLogLineLength > buffer; |
|
58 buffer.Append( _L( "[" ) ); // CSI: 78 # |
|
59 buffer.Append( RThread().Name() ); |
|
60 buffer.Append( _L( "] " ) ); // CSI: 78 # |
|
61 |
|
62 TIMPSOverflowTruncate overflow; |
|
63 |
|
64 VA_LIST list; |
|
65 VA_START( list, aFmt ); |
|
66 buffer.AppendFormatList( aFmt, list, &overflow ); |
|
67 |
|
68 |
|
69 #ifdef IMPS_DEBUG_OUTPUT_TO_FILE |
|
70 //Log goes to file |
|
71 RFileLogger logger; |
|
72 if ( logger.Connect() == KErrNone ) |
|
73 { |
|
74 logger.SetDateAndTime( ETrue, ETrue ); |
|
75 logger.CreateLog( KIMPSDebugOutputDir, |
|
76 KIMPSDebugOutputFileName, |
|
77 EFileLoggingModeAppend ); |
|
78 |
|
79 logger.Write( buffer ); |
|
80 logger.CloseLog(); |
|
81 logger.Close(); |
|
82 } |
|
83 |
|
84 #else |
|
85 |
|
86 //Log goes to default debug output |
|
87 RDebug::Print( _L( "%S" ), &buffer ); |
|
88 |
|
89 #endif //IMPS_DEBUG_OUTPUT_TO_FILE |
|
90 |
|
91 #endif //IMPS_ENABLE_DEBUG_PRINT |
|
92 } |
|
93 |
|
94 |
|
95 // End of File |
|
96 |
|
97 |