33// /
44// / \author Sylvain Chapeland, CERN
55
6-
76#ifndef SRC_SIMPLE_LOG_H
87#define SRC_SIMPLE_LOG_H
98
109#include < stdio.h>
1110#include < stdarg.h>
1211#include < memory>
1312
14- class SimpleLog {
13+ class SimpleLog
14+ {
1515
16- public:
17-
16+ public:
1817 // constructor
1918 // \param logFilePath Path to log file. If NULL, using stdout/stderr.
20- SimpleLog (const char * logFilePath= NULL );
19+ SimpleLog (const char * logFilePath = NULL );
2120
2221 // destructor
2322 ~SimpleLog ();
24-
23+
2524 // Set (or change) the log file name. Previous file used is closed. New file is appended when already existing.
25+ // Optionnaly, an automatic log rotation can be defined. Older files are renamed, appending .1, .2, .3, etc.
2626 // \param logFilePath Path to log file. If NULL, using stdout/stderr.
27- int setLogFile (const char * logFilePath=NULL );
27+ // \param rotateMaxBytes Maximum file size, after which a new file is created. If zero, no limit.
28+ // \param rotateMaxFiles Maximum number of files to keep (including the "current" file). If zero, no limit.
29+ // \param rotateNow If non-zero, the file is immediately rotated (independently of its size), otherwise it is appended.
30+ int setLogFile (const char * logFilePath = NULL ,
31+ unsigned long rotateMaxBytes = 0 , unsigned int rotateMaxFiles = 0 , unsigned int rotateNow = 0 );
2832
2933 // Change file descriptors used for stdout/stderr with provided ones
3034 // They must be valid for the lifetime of this object (or until overwritten), and are not closed.
@@ -36,33 +40,32 @@ class SimpleLog {
3640 ShowSeveritySymbol = 0x4 ,
3741 ShowMessage = 0x8
3842 };
39-
43+
4044 // Set output format based on (possibly OR-ed) format options from FormatOption enum
4145 void setOutputFormat (int opts);
42-
46+
4347 // Log an info message.
4448 // The message is formatted with timestamp and severity.
45- //
49+ //
4650 // \param message Message, in a printf-like compatible format (with associated extra arguments)
4751 // NB: attribute format for printf-like argument check -> 1st (invisible) arg is 'this'
48- int info (const char * message, ...) __attribute__ ((format (printf, 2 ,3 )));
52+ int info (const char * message, ...) __attribute__((format(printf, 2 , 3 )));
4953
5054 // Log an error message. See info().
51- int error (const char * message, ...) __attribute__ ((format (printf, 2 ,3 )));
52-
55+ int error (const char * message, ...) __attribute__((format(printf, 2 , 3 )));
56+
5357 // Log a warning message. See info().
54- int warning (const char *message, ...) __attribute__ ((format (printf, 2 ,3 )));
55-
56-
58+ int warning (const char * message, ...) __attribute__((format(printf, 2 , 3 )));
59+
5760 // explicitely disable automatically generated methods
5861 // disable copy constructor
59- SimpleLog (const SimpleLog&) =delete ;
62+ SimpleLog (const SimpleLog&) = delete ;
6063 // disable copy assignment operator
61- SimpleLog& operator =(const SimpleLog&) =delete ;
62-
63- private:
64- class Impl ; // private class for implementation
65- std::unique_ptr<Impl> pImpl; // handle to private class instance at runtime
64+ SimpleLog& operator =(const SimpleLog&) = delete ;
65+
66+ private:
67+ class Impl ; // private class for implementation
68+ std::unique_ptr<Impl> pImpl; // handle to private class instance at runtime
6669};
6770
6871#endif /* SRC_SIMPLE_LOG_H */
0 commit comments