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


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:19