📄 logwriter.cpp
字号:
/* Copyright (C) 2006 Lucas Gomez All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// INCLUDE FILES
#include "LogWriter.h"
#include "VncViewerAppUi.h"
// LITERALS
_LIT(KCrLf,"\r\n");
_LIT(KLogFile,"\\vncviewer.log");
_LIT(KFormatTime,"%F%M/%D/%Y %H:%T:%S ");
// CONSTANTS
const TInt KMaxLengthDate=20;
const TInt KUidLogWriterSingleton=1;
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CLogWriter::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CLogWriter* CLogWriter::NewL()
{
CLogWriter* self=NewLC();
CleanupStack::Pop(self);
return self;
}
// -----------------------------------------------------------------------------
// CLogWriter::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CLogWriter* CLogWriter::NewLC()
{
CLogWriter* self=new (ELeave) CLogWriter();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
// -----------------------------------------------------------------------------
// CLogWriter::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CLogWriter::ConstructL()
{
//Connect Session
User::LeaveIfError(iLogSession.Connect());
iLogSession.CreatePrivatePath(KDefaultDrive);
//Generate logs
GenerateLog(KLogFile); //KLogFile
}
// -----------------------------------------------------------------------------
// CLogWriter::CLogWriter()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CLogWriter::CLogWriter() : CCoeStatic(TUid::Uid(KUidLogWriterSingleton))
{
}
// ---------------------------------------------------------------------------
// CLogWriter::~CLogWriter()
// Destructor.
// ---------------------------------------------------------------------------
//
CLogWriter::~CLogWriter()
{
iLogFile.Close();
iLogSession.Close();
}
// -------------------------------------------------------------------------
// CMySingleton::InstanceL
// Returns an instance of this class. When called for the first time,
// a new instance is created and returned. After that, calling
// InstanceL returns the same instance that was created earlier.
// Note that the UID passed to CCoeEnv::Static needs to be unique.
// -------------------------------------------------------------------------
CLogWriter* CLogWriter::InstanceL()
{
CLogWriter* instance=static_cast<CLogWriter*>(CCoeEnv::Static(TUid::Uid(KUidLogWriterSingleton)));
if (!instance)
{
instance=CLogWriter::NewL();
}
return instance;
}
/*
* Funtion: GenerateLog()
*
* Description: Creates necessary log
*
* @param: const TDesC& aLogFilePath...file path of the file
* @return N/A
*/
void CLogWriter::GenerateLog(const TDesC& aLogFilePath)
{
TInt err=iLogFile.Replace(iLogSession,aLogFilePath,EFileWrite);
TFileText filetext;
filetext.Set(iLogFile);
filetext.Seek(ESeekEnd);
filetext.Write(KCrLf);
filetext.Write(KVersion);
}
/*
* LogTrace()
*
* Description: Sets log traces into the log file
*
* @param TDesC& aClassName Name of the class from where this method is called
* @param TDesC& aLogTrace Trace which is going to be printed into the log file
* @return N/A
*/
void CLogWriter::LogTrace(const TDesC& aLogTrace)
{
HBufC* auxLogDesC=auxLogDesC=HBufC::NewL(aLogTrace.Length()+KMaxLengthDate);
TPtr auxLogDesPtr=auxLogDesC->Des();
AddDate(aLogTrace,auxLogDesPtr);
Write(*auxLogDesC,KLogFile);
//Delete aux descriptor
if (auxLogDesC)
delete auxLogDesC;
}
/*
* Funtion: Write()
*
* @param: information to be written
* @param: path of the log file
* @return N/A
*/
void CLogWriter::Write(const TDesC& aInformation, const TDesC& aLogFilePath)
{
TFileText FileText;
FileText.Set(iLogFile);
FileText.Seek(ESeekEnd);
FileText.Write(aInformation);
}
/*
* Funtion: AddDate()
*
* @param: information to be written
* @param: destination hbufC where date string will be added plus source information
* @return N/A
*/
void CLogWriter::AddDate(const TDesC& aSourceData,TDes& aDestinatData)
{
aDestinatData.SetLength(0);
TTime hometime;
hometime.HomeTime();
hometime.FormatL(aDestinatData,KFormatTime);
aDestinatData.Append(aSourceData);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -