?? ltslog.cpp
字號:
/* * Ltslog.cpp - part of jEditLauncher package * Copyright (C) 2001 John Gellene * jgellene@nyc.rr.com * http://community.jedit.org * * This program 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 any later version. * * Notwithstanding the terms of the General Public License, the author grants * permission to compile and link object code generated by the compilation of * this program with object code and libraries that are not subject to the * GNU General Public License, provided that the executable output of such * compilation shall be distributed with source code on substantially the * same basis as the jEditLauncher package of which this program is a part. * By way of example, a distribution would satisfy this condition if it * included a working makefile for any freely available make utility that * runs on the Windows family of operating systems. This condition does not * require a licensee of this software to distribute any proprietary software * (including header files and libraries) that is licensed under terms * prohibiting redistribution to third parties. * * This program 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 program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: ltslog.cpp,v 1.4 2002/01/22 06:02:57 jgellene Exp $ *//* * Command line for compilation: * cl /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" * /D "_USRDLL" /D "LTSLOG_EXPORTS" /Fo"Release/" /Fd"Release/" /FD /c * /link /nologo /dll /incremental:no /pdb:"Release/ltslog.pdb" /machine:I386 * /out:"Release/ltslog.dll" /implib:"Release/ltslog.lib" ltslog.cpp */#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers#include <windows.h>#include <stdio.h>#include "ltslog.h"BOOL APIENTRY DllMain(HANDLE, DWORD, LPVOID){ return TRUE;}CLtslog::CLtslog(LPCTSTR szFileName) : hFile(0), dwWritten(0), msgLevel(Debug){ const char* szDefaultFileName = "jeditwin.log"; TCHAR path[MAX_PATH]; GetModuleFileName(NULL, path, MAX_PATH); char *pSlash = strrchr(path, '\\'); *++pSlash = 0; LPCTSTR szName = szFileName ? szFileName : szDefaultFileName; strcat(path, szName); // NOTE: log file opened with file sharing for reading and writing hFile = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, 0); if(hFile != 0) { SetFilePointer(hFile, 0, 0, FILE_END); InitLogEntry(true); }}CLtslog::~CLtslog(){ InitLogEntry(false); CloseHandle(hFile);}inlinevoid CLtslog::SetLogLevel(MsgLevel level){ msgLevel = level;}inlinevoid CLtslog::LogMessage(){ if(hFile != 0) { SetFilePointer(hFile, 0, 0, FILE_END); WriteFile(hFile, szMessage, strlen(szMessage), &dwWritten, 0); }}void CLtslog::LogImpl(bool bStamp, MsgLevel level, const char* lpszFormat, va_list args){ if((int)level > (int)msgLevel || (int)level < 0) return; const char* levels[] = { "Error ", "Warning ", "Notice ", "Message ", "Debug " }; const char* szFormat = "%04d-%02d-%02d %02d:%02d:%02d.%02d %s : "; if(bStamp) { SYSTEMTIME st; GetLocalTime(&st); sprintf(szMessage, szFormat, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds/10, levels[level]); LogMessage(); } vsprintf(szMessage, lpszFormat, args); LogMessage();}void CLtslog::InitLogEntry(bool bStart){ const char* months[] = { "", "Jan.", "Feb.", "Mar.", "Apr.", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec." }; const char* days[] = { "Sun.", "Mon.", "Tue.", "Wed.", "Thu.", "Fri.", "Sat." }; const char* szFormat = "jEditLauncher logging %s by module %s, %s %d, %d at %02d:%02d:%02d%s\n"; SYSTEMTIME st; GetLocalTime(&st); int hour = (int)((st.wHour + 11) % 12) + 1; sprintf(szMessage, szFormat, bStart ? "starting" : "finished", days[st.wDayOfWeek], months[st.wMonth], st.wDay, st.wYear, hour, st.wMinute, st.wSecond, (st.wHour > 11 ? "PM" : "AM")); LogMessage();}void CLtslog::Log(bool bStamp, MsgLevel level, const char* lpszFormat, ...){ if(lpszFormat == 0) return; va_list argList; va_start(argList, lpszFormat); LogImpl(bStamp, level, lpszFormat, argList); va_end(argList);}// exported functions:CLtslog* OpenLog(LPCTSTR szPath, MsgLevel level){ CLtslog *pLog = new CLtslog(szPath); if(pLog) pLog->SetLogLevel(level); return pLog;}void CloseLog(CLtslog* pLog){ delete pLog;}void SetLogLevel(CLtslog* pLog, MsgLevel level){ pLog->SetLogLevel(level);}void Log(CLtslog* pLog, bool bStamp, MsgLevel level, const char* lpszFormat, ...){ if(pLog == 0 || lpszFormat == 0) return; va_list argList; va_start(argList, lpszFormat); pLog->LogImpl(bStamp, level, lpszFormat, argList); va_end(argList);}void LogArgs(CLtslog* pLog, bool bStamp, MsgLevel level, const char* lpszFormat, va_list argList){ if(pLog == 0 || lpszFormat == 0) return; pLog->LogImpl(bStamp, level, lpszFormat, argList);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -