Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022
00023 #include "icl_core_logging/SQLiteLogOutput.h"
00024
00025 #include <iostream>
00026
00027 #include "icl_core_config/Config.h"
00028 #include "icl_core_logging/Logging.h"
00029
00030 namespace icl_core {
00031 namespace logging {
00032
00033 REGISTER_LOG_OUTPUT_STREAM(SQLite, &SQLiteLogOutput::create)
00034
00035 LogOutputStream *SQLiteLogOutput::create(const icl_core::String& name, const icl_core::String& config_prefix,
00036 icl_core::logging::LogLevel log_level)
00037 {
00038 return new SQLiteLogOutput(name, config_prefix, log_level);
00039 }
00040
00041 SQLiteLogOutput::SQLiteLogOutput(const icl_core::String& name, const icl_core::String& config_prefix,
00042 icl_core::logging::LogLevel log_level)
00043 : LogOutputStream(name, config_prefix, log_level),
00044 m_db(NULL)
00045 {
00046 icl_core::String db_filename = "";
00047 if (!icl_core::config::get<icl_core::String>(config_prefix + "/FileName", db_filename))
00048 {
00049 std::cerr << "SQLite log output: No filename specified for SQLite log output stream "
00050 << config_prefix << std::endl;
00051 }
00052
00053 bool rotate = false;
00054 icl_core::config::get<bool>(config_prefix + "/Rotate", rotate);
00055
00056 m_db = new SQLiteLogDb(db_filename, rotate);
00057 }
00058
00059 SQLiteLogOutput::~SQLiteLogOutput()
00060 {
00061 delete m_db;
00062 m_db = NULL;
00063 }
00064
00065 void SQLiteLogOutput::onStart()
00066 {
00067 m_db->openDatabase();
00068 }
00069
00070 void SQLiteLogOutput::pushImpl(const LogMessage& log_message)
00071 {
00072 m_db->writeLogLine("", log_message.timestamp.formatIso8601().c_str(), log_message.log_stream,
00073 logLevelDescription(log_message.log_level), log_message.filename,
00074 log_message.line, log_message.class_name, log_message.object_name,
00075 log_message.function_name, log_message.message_text);
00076 }
00077
00078 void SQLiteLogOutput::onShutdown()
00079 {
00080 m_db->closeDatabase();
00081 }
00082
00083 }
00084 }