Monobit Unity Networking ver.2.8.0 Server API Reference (C++)
MunLogger.hpp
Go to the documentation of this file.
1 
7 #ifndef __MUN_LOGGER_HPP__
8 #define __MUN_LOGGER_HPP__
9 
10 #include <typeinfo> // C++11 : typeid, std::type_info
11 #include <mrs.hpp>
12 
16 #ifndef MRSEXT_LOG_BUF_SIZE
17  #define MRSEXT_LOG_BUF_SIZE MRS_LOG_BUF_SIZE+512
18 #endif /* MRSEXT_LOG_BUF_SIZE */
19 
27 #define MRSEXT_OUTPUT_LOG( _level, _format, ... ) \
28 { \
29  char _msg[MRSEXT_LOG_BUF_SIZE]; \
30  std::string _extFormat = std::string("%s\t%s(%d)\t") + std::string(_format); \
31  snprintf( _msg, sizeof(_msg), _extFormat.c_str(), __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__ ); \
32  mrs_output_log( _level, _msg ); \
33 }
34 
41 #define MRSEXT_LOG_EMERG( _format, ... ) MRSEXT_OUTPUT_LOG( MRS_LOG_LEVEL_EMERG, _format, ##__VA_ARGS__ )
42 
49 #define MRSEXT_LOG_ALERT( _format, ... ) MRSEXT_OUTPUT_LOG( MRS_LOG_LEVEL_ALERT, _format, ##__VA_ARGS__ )
50 
57 #define MRSEXT_LOG_CRIT( _format, ... ) MRSEXT_OUTPUT_LOG( MRS_LOG_LEVEL_CRIT, _format, ##__VA_ARGS__ )
58 
65 #define MRSEXT_LOG_ERR( _format, ... ) MRSEXT_OUTPUT_LOG( MRS_LOG_LEVEL_ERR, _format, ##__VA_ARGS__ )
66 
73 #define MRSEXT_LOG_WARNING( _format, ... ) MRSEXT_OUTPUT_LOG( MRS_LOG_LEVEL_WARNING, _format, ##__VA_ARGS__ )
74 
81 #define MRSEXT_LOG_NOTICE( _format, ... ) MRSEXT_OUTPUT_LOG( MRS_LOG_LEVEL_NOTICE, _format, ##__VA_ARGS__ )
82 
89 #define MRSEXT_LOG_INFO( _format, ... ) MRSEXT_OUTPUT_LOG( MRS_LOG_LEVEL_INFO, _format, ##__VA_ARGS__ )
90 
97 #define MRSEXT_LOG_DEBUG( _format, ... ) MRSEXT_OUTPUT_LOG( MRS_LOG_LEVEL_DEBUG, _format, ##__VA_ARGS__ )
98 
103 {
104 public:
105  // ログローテート
106  enum MunLogRotate {
107  MUN_LOG_ROTATE_NONE = 0, // ローテートしない
108  MUN_LOG_ROTATE_DAILY = 1, // 日単位でローテート
109  };
110 
111 protected:
113  static std::string s_ProcessName;
114 
116  static FILE * s_pLogFile;
117 
119  static std::string s_LogFileName;
120 
122  static MunLogRotate s_LogRotate;
123 
125  static struct tm s_Updated;
126 
127 public:
132  static void SetLogRotate( MunLogRotate value ){ s_LogRotate = value; }
133 
134 public:
141  static void Initialize( std::string processName, bool isOutputLogFile, std::string outputLogFileName );
142 
146  static void Finalize();
147 
153  static void OnOutput( MrsLogLevel level, const char * msg );
154 
158  static void Reload();
159 
166  static bool Rotate( const char* src_file_name, const char* dst_file_name );
167 
168 private:
175  static void OutputFile( std::string ts, MrsLogLevel level, const char * msg );
176 
183  static void OutputConsole( std::string ts, MrsLogLevel level, const char * msg );
184 };
185 
186 #endif /* __MUN_LOGGER_HPP__ */
static void Finalize()
終了処理.
Definition: MunLogger.cpp:107
static std::string s_LogFileName
ログファイル名.
Definition: MunLogger.hpp:119
static struct tm s_Updated
最終更新日時.
Definition: MunLogger.hpp:125
static void SetLogRotate(MunLogRotate value)
ログローテートの設定.
Definition: MunLogger.hpp:132
static MunLogRotate s_LogRotate
ログローテート.
Definition: MunLogger.hpp:122
static FILE * s_pLogFile
ログファイル本体.
Definition: MunLogger.hpp:116
static bool Rotate(const char *src_file_name, const char *dst_file_name)
ローテート.
Definition: MunLogger.cpp:157
ログ管理クラス.
Definition: MunLogger.hpp:102
static void Initialize(std::string processName, bool isOutputLogFile, std::string outputLogFileName)
初期化処理.
Definition: MunLogger.cpp:80
static void Reload()
ログファイルの再読み込み.
Definition: MunLogger.cpp:144
static std::string s_ProcessName
プロセス名.
Definition: MunLogger.hpp:113
static void OnOutput(MrsLogLevel level, const char *msg)
ログの出力.
Definition: MunLogger.cpp:122