📄 log.h
字号:
/*+=============================================================================
File: log.h
Summary: This file defines log class.
History:
2000/05/30 V1.0
Start it by shencan@263.net
2000/06/01 V1.1
Add Size(), Empty() and Instance() method. (shencan@263.net)
2000/07/12 V1.2
Add check size timer. (shencan@263.net)
2000/07/19 V1.3
Add some maxium constant for log file size. (shencan@263.net)
2000/07/20 V1.4
Add maxium log file size value. (shencan@263.net)
2000/08/25 V1.5
Add log file maximum szie limit. (shencan@263.net)
============================================================================+*/
#ifndef _LOG_H
#define _LOG_H
#include <fstream.h>
//#include "ace/OS.h"
//#include "ace/Event_Handler.h"
//using namespace std;
// We define some parameters:
// when size is great than WARN_SIZE1, we set log level less than 4 or 4;
// when size is great than WARN_SIZE2, we set log level less than 3 or 3;
// when size is great than WARN_SIZE3, we set log level less than 2 or 2;
// when size is great than WARN_SIZE4, we set log level less than 1 or 1;
// when size is great than WARN_SIZE5, we set log level less than 0 or 0;
#define WARN_SIZE1 10240000L
#define WARN_SIZE2 20480000L
#define WARN_SIZE3 51200000L
#define WARN_SIZE4 204800000L
#define WARN_SIZE5 512000000L
#define FILE_NAME_LENGTH 256 // file name length
#define CHECK_LOG_TIME 10 // the interval time to check log file size
///////////////////////////////////////////////////////////////////////////////
// Debug and tracing
/**Class to encapsulate tracing functions.
This class does not require any instances and is only being used as a
method of grouping functions together in a name space.
*/
class RadTrace
{
public:
/** Set the stream to be used for trace output.
This stream is used for all trace output using the various trace functions
and macros.
*/
static void SetStream(ostream * out /** New output stream from trace. */ );
/// Options for trace output.
enum Options {
Blocks = 1,
/// Include date and time in all output
DateAndTime = 2,
/// Include (millisecond) timestamp in all output
Timestamp = 4,
/// Include identifier for thread trace is made from in all output
Thread = 8,
/// Include trace level in all output
TraceLevel = 16,
/// Include the file and line for the trace call in all output
FileAndLine = 32,
};
enum FileOption {
e_oneFile, // use only one file.
e_separateFile, // 10M is the upper size of log file
};
/** Set the trace options. */
static void SetOptions(unsigned options /** New level for trace */ );
/** Clear the trace options. */
static void ClearOptions(unsigned options /** New level for trace */ );
/** Get the current trace options. */
static unsigned GetOptions();
/** Set the trace level. */
static void SetLevel(unsigned level /** New level for trace */ );
/** Get the trace level. */
static unsigned GetLevel();
/** Determine if the level may cause trace output. */
static bool CanTrace(unsigned level);
/** Begin a trace output. */
static ostream & Begin(
unsigned level, /// Log level for output
const char * fileName, /// Filename of source file being traced
int lineNum /// Line number of source file being traced.
);
/** End a trace output. */
static ostream & End(ostream & strm /** Trace output stream being completed */);
};
#define RTRACE(level, args) \
if (!RadTrace::CanTrace(level)) ; else \
RadTrace::Begin(level, __FILE__, __LINE__) << args << RadTrace::End
///////////////////////////////////////////////////////////////////////////////
// class RadLogFile: Initial and close Radius log system
// Init() : Initial log system, set the log file name and level
// Close() : Close log system
// Size() : Get the size of log file
// Empty() : Empty log file
class RadLogFile
{
public:
//read config file, initial log file
int Init(int level, char * msg, char * controlFileName, int maxSize = 500,
RadTrace::FileOption op = RadTrace::e_separateFile);
int Close();
RadLogFile();
~RadLogFile();
long Size(); // get size of log file
bool Empty(); // empty this log file
// When program start, call it
int InitOpenFile();
// Open alternate log file stream
int RunningOpenFile();
int GetNumber();
int SaveNumber(int num);
static RadLogFile * Instance()
{
if ( m_instance == NULL )
m_instance = new RadLogFile;
return m_instance;
}
static RadLogFile * m_instance;
private:
fstream outputPtrace;
char m_fileName[FILE_NAME_LENGTH+1];
char m_alterFileName[FILE_NAME_LENGTH+1];
int m_alterNumber;
int m_maxLogSize;
int m_totalLogFile;
fstream m_controlStream;
// log control file name, such as "Radlog.ctl".
char m_controlFile[FILE_NAME_LENGTH+1];
public:
RadTrace::FileOption m_option;
//void CheckTimer(PTimer &, INT);
PDECLARE_NOTIFIER(PTimer, RadLogFile, CheckTimer);
PTimer timeLogger;
};
//class CLogTimer: public ACE_Event_Handler
//{
//public:
// CLogTimer(void) {};
// ~CLogTimer(void) {};
// virtual int handle_timeout( const ACE_Time_Value & tv, const void * arg);
//};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -