File: FileLog.h

package info (click to toggle)
between 6%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,532 kB
  • sloc: cpp: 28,110; php: 718; ansic: 638; objc: 245; sh: 236; makefile: 97; perl: 67
file content (95 lines) | stat: -rw-r--r-- 1,890 bytes parent folder | download | duplicates (10)
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
/*
 * Modification History
 *
 * 2002-February-25    Jason Rohrer
 * Created.  
 *
 * 2002-November-5    Jason Rohrer
 * Added support for backing up logs and deleting old log data.
 *
 * 2010-May-14    Jason Rohrer
 * String parameters as const to fix warnings.
 */


#include "minorGems/common.h"



#ifndef FILE_LOG_INCLUDED
#define FILE_LOG_INCLUDED



#include "PrintLog.h"

#include <stdio.h>


/**
 * A file-based implementation of the Log interface.
 *
 * @author Jason Rohrer
 */
class FileLog : public PrintLog {



    public:


        
        /**
         * Constructs a file log.
         *
         * @param inFileName the name of the file to write log messages to.
         *   Must be destroyed by caller.
         * @param inSecondsBetweenBackups the number of seconds to wait
         *   before making a backup of the current log file (deleting any
         *   old backups), clearing the current log file, and starting
         *   a fresh log in the current log file.  Defaults to 3600
         *   seconds (one hour).  Backup logs are saved to inFileName.bakup   
         */
        FileLog( const char *inFileName,
                 unsigned long inSecondsBetweenBackups = 3600 );


        
        virtual ~FileLog();

        

        /**
         * Makes a backup of the current log file, deletes old backups,
         * and clears the current log file.
         */
        void makeBackup();


        
        // overrides PrintLog::logString
        virtual void logString( const char *inLoggerName, const char *inString,
                                int inLevel );


        

    protected:

        FILE *mLogFile;

        char *mLogFileName;
                
        unsigned long mSecondsBetweenBackups;
        
        unsigned long mTimeOfLastBackup;
        
        
        static const char *mDefaultLogFileName;

        
    }; 



#endif