📄 logutils.cpp
字号:
/*
* Copyright (C) 2003-2007 Funambol, Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY, TITLE, NONINFRINGEMENT 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 program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
#include "stdafx.h"
#include <stdio.h>
#include "logutils.h"
static int logLevel = 0;
static FILE *logFile = NULL;
static wchar_t currentLogPath [256] = TEXT("/notlstnr.txt");
/**
* Print the message on a message box: no more used.
*/
void Print(TCHAR *pFormat, ...) {
va_list ArgList;
TCHAR Buffer[256];
va_start (ArgList, pFormat);
(void)wvsprintf (Buffer, pFormat, ArgList);
MessageBox(NULL, Buffer, TEXT(""), MB_OK);
va_end(ArgList);
}
/**
* Print the message on the log file.
*/
void DebugPrint(TCHAR *pFormat, ...) {
if(!logLevel)
return;
if(!logFile)
DebugInit(logLevel);
if(!logFile)
return;
va_list ArgList;
va_start (ArgList, pFormat);
vfwprintf(logFile, pFormat, ArgList);
fflush(logFile);
va_end(ArgList);
DebugEnd();
}
/**
* Open the log file.
*/
void DebugInit(int level, bool reset) {
if(logFile)
DebugEnd();
logLevel = level;
if(!logLevel)
return;
logFile = _wfopen(currentLogPath, (reset)?TEXT("w"):TEXT("a+"));
}
/**
* Closes the log file.
*/
void DebugEnd(void) {
if(logFile) {
fclose(logFile);
logFile=NULL;
}
}
/**
* Print the message written in exadecimal code.
*/
void HexDump(char *buf, int len){
if (logLevel<2)
return;
int i=0, byte;
for(i=0;i<len;i++){
if(i%8==0){
DebugPrint(L"\n%08x: ", i);
}
byte = buf[i];
DebugPrint(L"%02x%s", byte & 0xFF, (i%2)?" ":"");
}
DebugPrint(L"\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -