1 // ---------------------------------------------------------------------------------------------------------------------------------
4 // | | ___ __ _ __ _ ___ _ __ | |__
5 // | |/ _ \ / _` |/ _` |/ _ \ '__| | '_ \
6 // | | (_) | (_| | (_| | __/ | _ | | | |
7 // |_|\___/ \__, |\__, |\___|_| (_)|_| |_|
11 // Generic informational logging class
13 // ---------------------------------------------------------------------------------------------------------------------------------
15 // Restrictions & freedoms pertaining to usage and redistribution of this software:
17 // * This software is 100% free
18 // * If you use this software (in part or in whole) you must credit the author.
19 // * This software may not be re-distributed (in part or in whole) in a modified
20 // form without clear documentation on how to obtain a copy of the original work.
21 // * You may not use this software to directly or indirectly cause harm to others.
22 // * This software is provided as-is and without warrantee. Use at your own risk.
24 // For more information, visit HTTP://www.FluidStudios.com
26 // ---------------------------------------------------------------------------------------------------------------------------------
27 // Originally created on 07/06/2000 by Paul Nettle
29 // Copyright 2000, Fluid Studios, Inc., all rights reserved.
30 // ---------------------------------------------------------------------------------------------------------------------------------
35 // ---------------------------------------------------------------------------------------------------------------------------------
37 // ---------------------------------------------------------------------------------------------------------------------------------
42 // ---------------------------------------------------------------------------------------------------------------------------------
43 // Macros (necessary evil to take advantage of __LINE__ and __FILE__)
44 // ---------------------------------------------------------------------------------------------------------------------------------
46 #define LOG logger.sourceLine() = __LINE__, logger.sourceFile() = __FILE__,logger.logTex
47 #define HEX logger.sourceLine() = __LINE__, logger.sourceFile() = __FILE__,logger.logHex
48 #define RAW logger.sourceLine() = __LINE__, logger.sourceFile() = __FILE__,logger.logRaw
49 #define INDENT logger.sourceLine() = __LINE__, logger.sourceFile() = __FILE__,logger.indent
50 #define UNDENT logger.sourceLine() = __LINE__, logger.sourceFile() = __FILE__,logger.undent
51 #define LOGBLOCK logger.sourceLine() = __LINE__, logger.sourceFile() = __FILE__;LogBlock __lb__
53 // If you compiler supports __FUNCTION__, then replace the "#if 1" with "#if 0". Note that this will change the usage of the macro
56 #define LOGFUNC logger.sourceLine() = __LINE__, logger.sourceFile() = __FILE__;LogFlow __lf__
58 #define LOGFUNC logger.sourceLine() = __LINE__, logger.sourceFile() = __FILE__;LogFlow __lf__(__FUNCTION__)
61 // ---------------------------------------------------------------------------------------------------------------------------------
62 // The logger class: does the actual logging
63 // ---------------------------------------------------------------------------------------------------------------------------------
72 LOG_INDENT = 0x00000001,
73 LOG_UNDENT = 0x00000002,
74 LOG_FLOW = 0x00000004,
75 LOG_BLOK = 0x00000008,
76 LOG_DATA = 0x00000010,
77 LOG_INFO = 0x00000012,
78 LOG_WARN = 0x00000014,
80 LOG_CRIT = 0x00000020,
84 // Construction/Destruction
87 : _sourceLine(0), _indentCount(0), _indentChars(4), _fileSizeLimit(-1), _logMask(LOG_ALL),
88 _logStarted(false), _lineCharsFlag(false), _logFile("logger.log")
99 inline void operator +=(const string &s) {logTex(s);}
103 inline const bool &lineCharsFlag() const {return _lineCharsFlag;}
104 inline bool &lineCharsFlag() {return _lineCharsFlag;}
106 inline const int &fileSizeLimit() const {return _fileSizeLimit;}
107 inline int &fileSizeLimit() {return _fileSizeLimit;}
109 inline const unsigned int &logMask() const {return _logMask;}
110 inline unsigned int &logMask() {return _logMask;}
112 inline const string &logFile() const {return _logFile;}
113 inline string &logFile() {return _logFile;}
115 inline const unsigned int &sourceLine() const {return _sourceLine;}
116 inline unsigned int &sourceLine() {return _sourceLine;}
118 inline const string &sourceFile() const {return _sourceFile;}
119 inline string &sourceFile() {return _sourceFile;}
121 inline bool logStarted() const {return _logStarted;}
123 // Utilitarian (public)
125 virtual void start(const bool reset);
127 virtual void logTex(const string &s, const LogFlags logBits = LOG_INFO);
128 virtual void logRaw(const string &s);
129 virtual void logHex(const char *buffer, const unsigned int count, const LogFlags logBits = LOG_INFO);
130 virtual void indent(const string &s, const LogFlags logBits = LOG_INDENT);
131 virtual void undent(const string &s, const LogFlags logBits = LOG_UNDENT);
134 // Utilitarian (private)
136 virtual void limitFileSize() const;
137 virtual const string &headerString(const LogFlags logBits) const;
143 unsigned int _sourceLine;
147 unsigned int _logMask;
152 // ---------------------------------------------------------------------------------------------------------------------------------
153 // The LogBlock class: used for automatic indentation
154 // ---------------------------------------------------------------------------------------------------------------------------------
159 inline LogBlock(const string &s) {str = s;logger.indent("Begin block: " + str, Logger::LOG_INDENT);}
160 inline ~LogBlock() {logger.undent("", Logger::LOG_UNDENT);}
165 // ---------------------------------------------------------------------------------------------------------------------------------
166 // The LogFlow class: used for logging code flow
167 // ---------------------------------------------------------------------------------------------------------------------------------
172 inline LogFlow(const string &function) {str = function;logger.indent(str, Logger::LOG_FLOW);}
173 inline ~LogFlow() {logger.undent("", Logger::LOG_FLOW);}
179 // ---------------------------------------------------------------------------------------------------------------------------------
180 // logger.h - End of file
181 // ---------------------------------------------------------------------------------------------------------------------------------