Neo  0.5.0
Developer Documentation
Log.h
Go to the documentation of this file.
1 //========================================================================
2 // Copyright (c) 2012 Skaiware
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 //
8 // Permission is granted to anyone to use this software for any purpose,
9 // including commercial applications, and to alter it and redistribute it
10 // freely, subject to the following restrictions:
11 //
12 // 1. The origin of this software must not be misrepresented; you must not
13 // claim that you wrote the original software. If you use this software
14 // in a product, an acknowledgment in the product documentation would
15 // be appreciated but is not required.
16 //
17 // 2. Altered source versions must be plainly marked as such, and must not
18 // be misrepresented as being the original software.
19 //
20 // 3. This notice may not be removed or altered from any source
21 // distribution.
22 //
23 //========================================================================
24 
25 
26 #ifndef __LOG
27 #define __LOG
28 
29 #include <ostream>
30 #include <iostream>
31 #include <sstream>
32 #include <fstream>
33 
34 namespace Neo
35 {
36 
37 /* Log function compatible with the syslog standard, usefull for filtering logs, and logging networkly (todo).
38  0 Emergency emerg (panic) System is unusable. A "panic" condition usually affecting multiple apps/servers/sites. At this level it would usually notify all tech staff on call.
39  1 Alert alert Action must be taken immediately. Should be corrected immediately, therefore notify staff who can fix the problem. An example would be the loss of a primary ISP connection.
40  2 Critical crit Critical conditions. Should be corrected immediately, but indicates failure in a primary system, an example is a loss of a backup ISP connection.
41  3 Error err (error) Error conditions. Non-urgent failures, these should be relayed to developers or admins; each item must be resolved within a given time.
42  4 Warning warning (warn) Warning conditions. Warning messages, not an error, but indication that an error will occur if action is not taken, e.g. file system 85% full - each item must be resolved within a given time.
43  5 Notice notice Normal but significant condition. Events that are unusual but not error conditions - might be summarized in an email to developers or admins to spot potential problems - no immediate action required.
44  6 Informational info Informational messages. Normal operational messages - may be harvested for reporting, measuring throughput, etc. - no action required.
45  7 Debug debug Debug-level messages. Info useful to developers for debugging the application, not useful during operations.
46 */
47 
48 // For exposure to Lua
49 void NEO_ENGINE_EXPORT infoLog(const char* s, const char* function, const char* filename, int line);
50 
51 #ifndef SWIG
52 // Only give the filename and not the path
53 #ifndef WIN32
54 #define __SFILENAME__ \
55 (strrchr(__FILE__,'/') \
56 ? strrchr(__FILE__,'/')+1 \
57 : __FILE__ \
58 )
59 #else
60 #define __SFILENAME__ \
61 (strrchr(__FILE__,'\\') \
62 ? strrchr(__FILE__,'\\')+1 \
63 : __FILE__ \
64 )
65 #endif
66 
67 // for the moment let s just simply log if the message has a severity lower than the env variable
68 #define MLOG(severity, USERMESSAGE) { Neo::Log::m_stringstream.str(std::string("")); Neo::Log::m_stringstream<<USERMESSAGE; Neo::Log::m_string=Neo::Log::m_stringstream.str(); Neo::Log::log(severity, __FUNCTION__, __SFILENAME__, __LINE__); }
69 
70 // common helpers
71 #define MLOG_ERROR(USERMESSAGE) MLOG(3, USERMESSAGE)
72 #define MLOG_WARNING(USERMESSAGE) MLOG(4, USERMESSAGE)
73 #define MLOG_INFO(USERMESSAGE) MLOG(6, USERMESSAGE)
74 #define MLOG_DEBUG(USERMESSAGE) MLOG(7, USERMESSAGE)
75 
76 class NEO_ENGINE_EXPORT Log
77 {
78 private:
79 
80  // private constructor
81  Log();
82  ~Log();
83 
84  static Log * m_instance;
85  static fstream m_logfstream;
86  static int m_desired_loglevel;
87 
88 public:
89 
90  static stringstream m_stringstream;
91  static string m_string;
92  static void log(int severity, const char * func, const char * fil, const int & line_no);
93 };
94 #endif // SWIG
95 
96 }
97 #endif
static stringstream m_stringstream
Definition: Log.h:90
Definition: Log.h:76
void NEO_ENGINE_EXPORT infoLog(const char *s, const char *function, const char *filename, int line)
Definition: Color.h:29
static string m_string
Definition: Log.h:91