|
1 // Copyright (c) 2000-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifdef _DEBUG |
|
17 #undef _MSG_NO_LOGGING |
|
18 #endif |
|
19 |
|
20 |
|
21 #include <e32cons.h> |
|
22 #include <flogger.h> |
|
23 #include <e32svr.h> |
|
24 #include <watcher.h> |
|
25 |
|
26 #ifndef _MSG_NO_LOGGING |
|
27 _LIT(KWatcherLogDir, "watcher"); |
|
28 _LIT(KWatcherLogDirFull, "c:\\logs\\watcher"); |
|
29 _LIT(KWatcherLogDirConsole, "c:\\logs\\watcher\\cons"); |
|
30 _LIT(KWatcherLogFile, "watcher.txt"); |
|
31 _LIT(KWatcherConsoleTitle, "Messaging Watchers"); |
|
32 #endif |
|
33 |
|
34 CWatcherLog* CWatcherLog::NewL(RFs& aFs) |
|
35 { |
|
36 CWatcherLog* self = new (ELeave) CWatcherLog(aFs); |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop(); |
|
40 return self; |
|
41 } |
|
42 |
|
43 CWatcherLog::CWatcherLog(RFs& aFs) |
|
44 : CBase(), iFs(aFs) |
|
45 { |
|
46 } |
|
47 |
|
48 CWatcherLog::~CWatcherLog() |
|
49 { |
|
50 delete iConsole; |
|
51 } |
|
52 |
|
53 void CWatcherLog::ConstructL() |
|
54 { |
|
55 #ifndef _MSG_NO_LOGGING |
|
56 if (IsConsole()) |
|
57 iConsole = Console::NewL(KWatcherConsoleTitle, TSize(KConsFullScreen, KConsFullScreen)); |
|
58 #endif |
|
59 } |
|
60 |
|
61 #ifndef _MSG_NO_LOGGING |
|
62 EXPORT_C void CWatcherLog::Printf(TRefByValue<const TDesC> aFmt,...) |
|
63 #else |
|
64 EXPORT_C void CWatcherLog::Printf(TRefByValue<const TDesC> /*aFmt*/,...) |
|
65 #endif |
|
66 { |
|
67 #ifndef _MSG_NO_LOGGING |
|
68 VA_LIST list; |
|
69 VA_START(list, aFmt); |
|
70 |
|
71 // Print to log file |
|
72 TBuf<KWatcherLogBuffer> buf; |
|
73 buf.FormatList(aFmt, list); |
|
74 |
|
75 // Write to log file |
|
76 RFileLogger::Write(KWatcherLogDir, KWatcherLogFile, EFileLoggingModeAppend, buf); |
|
77 |
|
78 // Write to console |
|
79 if (iConsole) |
|
80 { |
|
81 buf.Append('\n'); |
|
82 iConsole->Printf(KWatcherStringFormat, &buf); |
|
83 } |
|
84 #endif |
|
85 } |
|
86 |
|
87 #ifndef _MSG_NO_LOGGING |
|
88 EXPORT_C void CWatcherLog::Printf(TRefByValue<const TDesC8> aFmt,...) |
|
89 #else |
|
90 EXPORT_C void CWatcherLog::Printf(TRefByValue<const TDesC8> /*aFmt*/,...) |
|
91 #endif |
|
92 { |
|
93 #ifndef _MSG_NO_LOGGING |
|
94 VA_LIST list; |
|
95 VA_START(list, aFmt); |
|
96 |
|
97 // Print to log file |
|
98 TBuf8<KWatcherLogBuffer> buf; |
|
99 buf.FormatList(aFmt, list); |
|
100 |
|
101 // Write to log file |
|
102 RFileLogger::Write(KWatcherLogDir, KWatcherLogFile, EFileLoggingModeAppend, buf); |
|
103 |
|
104 // Write to console |
|
105 if (iConsole) |
|
106 { |
|
107 buf.Append('\n'); |
|
108 iConsole->Printf(KWatcherStringFormat, &buf); |
|
109 } |
|
110 #endif |
|
111 } |
|
112 |
|
113 EXPORT_C TBool CWatcherLog::IsLogging() const |
|
114 { |
|
115 #ifndef _MSG_NO_LOGGING |
|
116 TUint att; |
|
117 return (iFs.Att(KWatcherLogDirFull, att) == KErrNone); |
|
118 #else |
|
119 return EFalse; |
|
120 #endif |
|
121 } |
|
122 |
|
123 |
|
124 TBool CWatcherLog::IsConsole() const |
|
125 { |
|
126 #ifndef _MSG_NO_LOGGING |
|
127 TUint att; |
|
128 return (iFs.Att(KWatcherLogDirConsole, att) == KErrNone); |
|
129 #else |
|
130 return EFalse; |
|
131 #endif |
|
132 } |