|
1 // Copyright (c) 1997-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 // Dummy SAT TSY logger |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include "Dsatlog.h" |
|
23 |
|
24 #ifdef __LOGGER__ |
|
25 #ifdef __EXE__ |
|
26 GLDEF_D CDTSYLogger* CDTSYLogger; |
|
27 #endif |
|
28 |
|
29 _LIT(KLogFileName,"C:\\DSATTSY.LOG"); |
|
30 #define KGenericBufferSize (150) |
|
31 |
|
32 CDTSYLogger* CDTSYLogger::NewL() |
|
33 { |
|
34 CDTSYLogger* logger=new(ELeave) CDTSYLogger(); |
|
35 CleanupStack::PushL(logger); |
|
36 logger->ConstructL(); |
|
37 CleanupStack::Pop(); |
|
38 return logger; |
|
39 } |
|
40 |
|
41 CDTSYLogger::CDTSYLogger() : iValid(EFalse) |
|
42 {} |
|
43 |
|
44 void CDTSYLogger::ConstructL() |
|
45 /** |
|
46 * In debug mode the logfile will not be deleted at start of new session |
|
47 */ |
|
48 { |
|
49 iFs.Connect(); |
|
50 TInt ret=KErrNone; |
|
51 ret=iFile.Open(iFs,KLogFileName,EFileShareAny|EFileWrite); |
|
52 if(ret!=KErrNone) |
|
53 ret=iFile.Create(iFs,KLogFileName,EFileShareAny|EFileWrite); |
|
54 if(ret==KErrNone) |
|
55 { |
|
56 iValid=ETrue; |
|
57 TInt aPos=0; |
|
58 iFile.Seek(ESeekEnd,aPos); |
|
59 ret=iFile.Write(_L8("----------New Log----------\015\012")); |
|
60 } |
|
61 } |
|
62 |
|
63 void CDTSYLogger::Destruct() |
|
64 { |
|
65 #ifdef __EXE__ |
|
66 CDTSYLogger* context=aScriptLoggerContext; |
|
67 delete context; |
|
68 aScriptLoggerContext=NULL; |
|
69 #else |
|
70 CDTSYLogger* context=(CDTSYLogger*) Dll::Tls(); |
|
71 delete context; |
|
72 Dll::SetTls(NULL); |
|
73 #endif |
|
74 } |
|
75 |
|
76 CDTSYLogger::~CDTSYLogger() |
|
77 { |
|
78 if(iValid) |
|
79 iFile.Close(); |
|
80 iFs.Close(); |
|
81 } |
|
82 |
|
83 void CDTSYLogger::Write(const TDesC8& aText) |
|
84 { |
|
85 #ifdef __EXE__ |
|
86 CDTSYLogger* context=aScriptLoggerContext; |
|
87 #else |
|
88 CDTSYLogger* context=(CDTSYLogger*) Dll::Tls(); |
|
89 #endif |
|
90 if(context==NULL) |
|
91 { |
|
92 TRAPD(ret,context=CDTSYLogger::NewL()); |
|
93 if (ret==KErrNone) |
|
94 { |
|
95 #ifdef __EXE__ |
|
96 aScriptLoggerContext=context; |
|
97 #else |
|
98 Dll::SetTls(context); |
|
99 #endif |
|
100 } |
|
101 else return; |
|
102 } |
|
103 if(context->iValid) |
|
104 context->WriteRecord(aText); |
|
105 } |
|
106 |
|
107 void CDTSYLogger::WriteFormat(TRefByValue<const TDesC8> aFmt,...) |
|
108 { |
|
109 TBuf8<KGenericBufferSize> buf; |
|
110 VA_LIST list; |
|
111 VA_START(list,aFmt); |
|
112 buf.FormatList(aFmt,list); |
|
113 TChar tmpchar; |
|
114 for(TInt i=0;i<buf.Length();i++) |
|
115 { |
|
116 tmpchar=buf[i]; |
|
117 if(!((tmpchar.IsPrint()) || (tmpchar=='\n') || (tmpchar=='\r') || (tmpchar=='\t'))) |
|
118 buf[i]='.'; |
|
119 } |
|
120 #ifdef __EXE__ |
|
121 CDTSYLogger* context=aScriptLoggerContext; |
|
122 #else |
|
123 CDTSYLogger* context=(CDTSYLogger*) Dll::Tls(); |
|
124 #endif |
|
125 if(context==NULL) |
|
126 { |
|
127 TRAPD(ret,context=CDTSYLogger::NewL()); |
|
128 if (ret==KErrNone) |
|
129 { |
|
130 #ifdef __EXE__ |
|
131 aScriptLoggerContext=context; |
|
132 #else |
|
133 Dll::SetTls(context); |
|
134 #endif |
|
135 } |
|
136 else return; |
|
137 } |
|
138 if(context->iValid) |
|
139 context->WriteRecord(buf); |
|
140 } |
|
141 |
|
142 void CDTSYLogger::WriteRecord(const TDesC8& aText) |
|
143 { |
|
144 if(iValid) |
|
145 { |
|
146 TBuf8<KGenericBufferSize> buf; |
|
147 TTime now; |
|
148 now.UniversalTime(); |
|
149 TDateTime dateTime; |
|
150 dateTime = now.DateTime(); |
|
151 buf.Format(_L8 ("%04d/%02d/%02d %02d.%02d:%02d:%06d "),dateTime.Year(),dateTime.Month()+1, dateTime.Day()+1,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
152 buf.AppendFormat(_L8("%S\015\012"),&aText); |
|
153 iFile.Write(buf); |
|
154 iFile.Flush(); |
|
155 } |
|
156 } |
|
157 |
|
158 #endif |