OSDN Git Service

logging処理の追加
authorcaprice <caprice@users.sourceforge.jp>
Sat, 9 Aug 2014 16:38:16 +0000 (01:38 +0900)
committercaprice <caprice@users.sourceforge.jp>
Sat, 9 Aug 2014 16:38:16 +0000 (01:38 +0900)
src/GikoMona.cpp

index 6fa0a3f..7358ff9 100644 (file)
 #include "GikoMona.hpp"
 #include "database.hpp"
 #include "model.hpp"
-#include "post-office.hpp"
+#include "communication/post-office.hpp"
 
 #include "extension.hpp"
 
+namespace monazilla { namespace GikoMona {
+
+const char* severity_names[] = {
+    "debug_trace",
+    "debug_message",
+    "debug_warning",
+    "debug_error",
+    
+    "trace",
+    "message",
+    "warning",
+    "error",
+};
+    
+boost::log::sources::severity_logger<severity_level>* severity_logger;
+
+} }
+
+std::ostream& operator<<(std::ostream& strm, const monazilla::GikoMona::severity_level level) {
+    strm << monazilla::GikoMona::severity_names[static_cast<int>(level)];
+    return strm;
+}
+
 namespace monazilla { namespace GikoMona { namespace core {
 
 namespace {
@@ -26,6 +49,15 @@ std::shared_ptr<communication::post_office> app_postoffice;
 }
 
 bool init_core(const mona_string& app_name) {
+    severity_logger = new boost::log::sources::severity_logger<severity_level>;
+    boost::log::register_simple_formatter_factory<severity_level, char>( "Severity" );
+    boost::log::add_file_log(
+        boost::log::keywords::file_name = "logs/%Y%m%d.log",
+        boost::log::keywords::format = "%Severity% - [GikoMona. %TimeStamp%]:%Message%",
+        boost::log::keywords::open_mode = (std::ios::out | std::ios::app)
+    );
+    boost::log::core::get()->add_global_attribute("TimeStamp", boost::log::attributes::local_clock());
+    
     wxXmlResource::Get()->InitAllHandlers();
     wxXmlResource::Get()->LoadAllFiles(wxT("resouce"));
     
@@ -36,7 +68,8 @@ bool init_core(const mona_string& app_name) {
     // 一時解凍ファイルなどを溜め込む .tmp フォルダを作成
     if(!boost::filesystem::exists(path_builder.str(), reason) &&
        !boost::filesystem::create_directories(path_builder.str(), reason)) {
-        // log
+        ERROR(".tmpフォルダがすでに存在するか、.tmpフォルダの作成に失敗しました。");
+        MESSAGE(".tmpフォルダが存在するか確認し、存在すれば.tmpフォルダを削除してください。");
         std::terminate();
     }