SQLiteLogOutput.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
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 }


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:24