1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/* Copyright (C) 2003 MySQL AB
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; version 2 of the License.
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 */
#ifndef FILELOGHANDLER_H
#define FILELOGHANDLER_H
#include "LogHandler.hpp"
class File_class;
/**
* Logs messages to a file. The log file will be archived depending on
* the file's size or after N number of log entries.
* There will be only a specified number of archived logs
* which will be "recycled".
*
* The archived log file will be named as <filename>.1..N.
*
*
* @see LogHandler
* @version #@ $Id: FileLogHandler.hpp,v 1.2 2003/09/01 10:15:53 innpeno Exp $
*/
class FileLogHandler : public LogHandler
{
public:
/** Max number of log files to archive. */
STATIC_CONST( MAX_NO_FILES = 6 );
/** Max file size of the log before archiving. */
STATIC_CONST( MAX_FILE_SIZE = 1024000 );
/** Max number of log entries before archiving. */
STATIC_CONST( MAX_LOG_ENTRIES = 10000 );
/**
* Default constructor.
*/
FileLogHandler();
/**
* Creates a new file handler with the specified filename,
* max number of archived log files and max log size for each log.
*
* @param aFileName the log filename.
* @param maxNoFiles the maximum number of archived log files.
* @param maxFileSize the maximum log file size before archiving.
* @param maxLogEntries the maximum number of log entries before checking time to archive.
*/
FileLogHandler(const char* aFileName,
int maxNoFiles = MAX_NO_FILES,
long maxFileSize = MAX_FILE_SIZE,
unsigned int maxLogEntries = MAX_LOG_ENTRIES);
/**
* Destructor.
*/
virtual ~FileLogHandler();
virtual bool open();
virtual bool close();
virtual bool setParam(const BaseString ¶m, const BaseString &value);
virtual bool checkParams();
protected:
virtual void writeHeader(const char* pCategory, Logger::LoggerLevel level);
virtual void writeMessage(const char* pMsg);
virtual void writeFooter();
private:
/** Prohibit */
FileLogHandler(const FileLogHandler&);
FileLogHandler operator = (const FileLogHandler&);
bool operator == (const FileLogHandler&);
/**
* Returns true if it is time to create a new log file.
*/
bool isTimeForNewFile();
/**
* Archives the current log file and creates a new one.
* The archived log filename will be in the format of <filename>.N
*
* @return true if successful.
*/
bool createNewFile();
bool setFilename(const BaseString &filename);
bool setMaxSize(const BaseString &size);
bool setMaxFiles(const BaseString &files);
int m_maxNoFiles;
off_t m_maxFileSize;
unsigned int m_maxLogEntries;
File_class* m_pLogFile;
};
#endif
|