FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
logging.h
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Sep 30, 2010
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2010 Facebook, Inc
13 \**********************************************************/
14 
15 #pragma once
16 #ifndef H_FB_LOGGING
17 #define H_FB_LOGGING
18 
19 #include <sstream>
20 #include <string>
21 #include <list>
22 
23 #if !FB_NO_LOGGING_MACROS
24 # if defined(__GNUC__)
25 # define FBLOG_FUNCTION() __PRETTY_FUNCTION__
26 # elif defined(_MSC_VER)
27 # define FBLOG_FUNCTION() __FUNCTION__
28 # else
29 # define FBLOG_FUNCTION() __func__
30 # endif
31 # define FBLOG_LOG_BODY(type, src, msg) \
32  do { \
33  std::ostringstream os; \
34  os << msg; \
35  FB::Log:: type (src, os.str(), __FILE__, __LINE__, FBLOG_FUNCTION()); \
36  } while(0)
37 #endif
38 
39 #if !FB_NO_LOGGING_MACROS
40 # define FBLOG_TRACE(src, msg) FBLOG_LOG_BODY(trace, src, msg)
41 # define FBLOG_DEBUG(src, msg) FBLOG_LOG_BODY(debug, src, msg)
42 # define FBLOG_INFO(src, msg) FBLOG_LOG_BODY(info, src, msg)
43 # define FBLOG_WARN(src, msg) FBLOG_LOG_BODY(warn, src, msg)
44 # define FBLOG_ERROR(src, msg) FBLOG_LOG_BODY(error, src, msg)
45 # define FBLOG_FATAL(src, msg) FBLOG_LOG_BODY(fatal, src, msg)
46 #else
47 # define FBLOG_TRACE(src, msg)
48 # define FBLOG_DEBUG(src, msg)
49 # define FBLOG_INFO(src, msg)
50 # define FBLOG_WARN(src, msg)
51 # define FBLOG_ERROR(src, msg)
52 # define FBLOG_FATAL(src, msg)
53 #endif
54 
55 namespace FB { namespace Log {
56 
57  void initLogging();
58  void stopLogging();
59 
60  void trace(const std::string& src, const std::string& msg, const char *file, int line, const char *fn);
61  void debug(const std::string& src, const std::string& msg, const char *file, int line, const char *fn);
62  void info(const std::string& src, const std::string& msg, const char *file, int line, const char *fn);
63  void warn(const std::string& src, const std::string& msg, const char *file, int line, const char *fn);
64  void error(const std::string& src, const std::string& msg, const char *file, int line, const char *fn);
65  void fatal(const std::string& src, const std::string& msg, const char *file, int line, const char *fn);
66 
70  enum LogLevel {
71  // All log messages, no matter how small
72  LogLevel_Trace = 0x01,
73  // Debug level log messages - messages you won't care about unless you're debugging
74  LogLevel_Debug = 0x02,
75  // Informational log messages - not critical to know, but you might care
76  LogLevel_Info = 0x04,
77  // Only log warning and worse messages
78  LogLevel_Warn = 0x08,
79  // Only log messages that are actual errors
80  LogLevel_Error = 0x10
81  };
82 
92  enum LogMethod {
93  // Enable Console-mode logging (Debug console on windows, system console on other)
94  LogMethod_Console = 0x01,
95  // Enable logging to a file - filename must be specified
96  LogMethod_File = 0x02
97  };
98 
107  typedef std::list<std::pair<FB::Log::LogMethod, std::string> > LogMethodList;
108 
109 }; };
110 
111 #endif
112