|
1 // Copyright (c) 1995-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 // code for the F32 derived class |
|
15 // |
|
16 // |
|
17 |
|
18 #include "../SERVER/w32cmd.h" |
|
19 #include "DEBLOGFL.H" |
|
20 |
|
21 #define __FORCE_ASCII yes |
|
22 |
|
23 #define DEFAULT_LOG_FILE_NAME _L("C:\\private\\10003b20\\WSERV.LOG") |
|
24 |
|
25 /*#if defined(__WINS__) |
|
26 #pragma data_seg(".E32_UID") |
|
27 __WINS_UID(0, KWservLoggingDllUidValue, 0) |
|
28 #pragma data_seg() |
|
29 #endif*/ |
|
30 |
|
31 |
|
32 EXPORT_C CDebugLogBase *CreateDebugLog(TBool aIsFirst, TDesC &aParams) |
|
33 { |
|
34 CDebugLogFile *device=new(ELeave) CDebugLogFile(); |
|
35 CDebugLog *log=NULL; |
|
36 TRAPD(err,log=new(ELeave) CDebugLog(device)); |
|
37 if (err!=KErrNone) |
|
38 { |
|
39 delete device; |
|
40 User::Leave(err); |
|
41 } |
|
42 TRAP(err,log->ConstructL(aIsFirst, aParams)); |
|
43 if (err!=KErrNone) |
|
44 { |
|
45 delete log; |
|
46 User::Leave(err); |
|
47 } |
|
48 return(log); |
|
49 } |
|
50 |
|
51 CDebugLogFile::CDebugLogFile() |
|
52 { |
|
53 __DECLARE_NAME(_S("CDebugLogFile")); |
|
54 } |
|
55 |
|
56 CDebugLogFile::~CDebugLogFile() |
|
57 { |
|
58 iFile.Close(); |
|
59 iFs.Close(); |
|
60 } |
|
61 |
|
62 void CDebugLogFile::ConstructL(TBool aIsFirst, TDesC &aParams) |
|
63 { |
|
64 TPtrC defaultFileName(DEFAULT_LOG_FILE_NAME); |
|
65 TDesC *fileName=&aParams; |
|
66 if (aParams.Length()==0) |
|
67 fileName=&defaultFileName; |
|
68 User::LeaveIfError(iFs.Connect()); |
|
69 //_LIT(KLog1,"Connected To File Server"); |
|
70 //RDebug::Print(KLog1); |
|
71 iFs.MkDirAll(*fileName); |
|
72 if (aIsFirst) |
|
73 { |
|
74 User::LeaveIfError(iFile.Replace(iFs,*fileName,EFileStreamText|EFileWrite|EFileShareReadersOrWriters)); |
|
75 //_LIT(KLog2,"Replaced File 1"); |
|
76 //RDebug::Print(KLog2); |
|
77 #if !defined(__FORCE_ASCII) |
|
78 TUint16 feffInt=0xFEFF; |
|
79 User::LeaveIfError(iFile.Write(TPtrC8((TUint8 *)&feffInt,2))); |
|
80 #endif |
|
81 } |
|
82 else |
|
83 { |
|
84 TInt err=iFile.Open(iFs,*fileName,EFileStreamText|EFileWrite|EFileShareReadersOrWriters); |
|
85 //_LIT(KLog3,"Done ReOpen"); |
|
86 //RDebug::Print(KLog3); |
|
87 if (err==KErrNone) |
|
88 { |
|
89 TInt seekpos; |
|
90 User::LeaveIfError(iFile.Seek(ESeekEnd,seekpos)); |
|
91 } |
|
92 else |
|
93 User::LeaveIfError(iFile.Replace(iFs,*fileName,EFileStreamText|EFileWrite|EFileShareReadersOrWriters)); |
|
94 } |
|
95 iEol16=TPtrC16((TUint16 *)_S("\r\n")); |
|
96 iEol.Set((TUint8 *)iEol16.Ptr(),iEol16.Size()); |
|
97 iEol8=TPtrC8((TUint8 *)"\r\n"); |
|
98 } |
|
99 |
|
100 void CDebugLogFile::WriteToLogL(const TDesC &aDes, const TDesC &aDes2) |
|
101 { |
|
102 #if defined(__FORCE_ASCII) |
|
103 TBuf8<128> des1; |
|
104 TBuf8<160> des2; |
|
105 des1.Copy(aDes); |
|
106 des2.Copy(aDes2); |
|
107 WriteToLog8L(des1,des2); |
|
108 #else |
|
109 User::LeaveIfError(iFile.Write(TPtrC8((TUint8 *)aDes.Ptr(),aDes.Size()))); |
|
110 User::LeaveIfError(iFile.Write(iEol)); |
|
111 User::LeaveIfError(iFile.Write(TPtrC8((TUint8 *)aDes2.Ptr(),aDes2.Size()))); |
|
112 iFile.Flush(); //Ignore Error |
|
113 #endif |
|
114 } |
|
115 |
|
116 void CDebugLogFile::WriteToLog8L(const TDesC8 &aDes, const TDesC8 &aDes2) |
|
117 { |
|
118 User::LeaveIfError(iFile.Write(aDes)); |
|
119 User::LeaveIfError(iFile.Write(iEol8)); |
|
120 User::LeaveIfError(iFile.Write(aDes2)); |
|
121 iFile.Flush(); //Ignore Error |
|
122 } |
|
123 |