1 /* |
|
2 * Copyright (c) 2005-2009 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 "T_log.h" |
|
20 |
|
21 #define DES_AS_8_BIT(str) (TPtrC8((TText8*)((str).Ptr()), (str).Size())) |
|
22 _LIT8(KLimit,"\r\n"); |
|
23 _LIT8(KTimeFormat, "%2d:%2d:%3d "); |
|
24 |
|
25 CLog::CLog() |
|
26 { |
|
27 |
|
28 } |
|
29 |
|
30 CLog::~CLog() |
|
31 { |
|
32 iFile.Close(); |
|
33 |
|
34 iBuf.Close(); |
|
35 } |
|
36 |
|
37 CLog* CLog::NewLC(RFs &aFs, const TDesC &aFileName) |
|
38 { |
|
39 CLog* self = new (ELeave)CLog(); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(aFs,aFileName); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CLog* CLog::NewL(RFs &aFs, const TDesC &aFileName) |
|
46 { |
|
47 CLog* self=CLog::NewLC(aFs, aFileName); |
|
48 CleanupStack::Pop(); // self; |
|
49 return self; |
|
50 } |
|
51 |
|
52 void CLog::ConstructL(RFs &aFs, const TDesC &aFileName) |
|
53 { |
|
54 User::LeaveIfError(iFile.Replace(aFs,aFileName,EFileWrite|EFileShareAny)); |
|
55 |
|
56 iText.Set(iFile); |
|
57 iBuf.Create(1024); |
|
58 |
|
59 } |
|
60 //write log |
|
61 //input: aInfo, text msg; |
|
62 //return: KErrNone, ok; other, fail; |
|
63 TInt CLog::WriteLog(const TDesC& aInfo) |
|
64 { |
|
65 TTime currentTime; |
|
66 currentTime.HomeTime(); |
|
67 TDateTime time=currentTime.DateTime(); |
|
68 |
|
69 iBuf.Format(KTimeFormat,time.Minute(),time.Second(),time.MicroSecond()); |
|
70 iBuf.Append(aInfo); |
|
71 |
|
72 iFile.Write(iBuf); |
|
73 iFile.Write(KLimit); |
|
74 |
|
75 return 0; |
|
76 } |
|
77 |
|
78 //write log |
|
79 //input: aInfo, text msg; |
|
80 //return: KErrNone, ok; other, fail; |
|
81 TInt CLog::WriteLog(const TDesC8& aInfo) |
|
82 { |
|
83 TTime currentTime; |
|
84 currentTime.HomeTime(); |
|
85 TDateTime time=currentTime.DateTime(); |
|
86 |
|
87 iBuf.Format(KTimeFormat,time.Minute(),time.Second(),time.MicroSecond()); |
|
88 iBuf.Append(aInfo); |
|
89 |
|
90 iFile.Write(iBuf); |
|
91 iFile.Write(KLimit); |
|
92 |
|
93 return 0; |
|
94 } |
|