SQLiteLogOutput.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
24 
25 #include <iostream>
26 
27 #include "icl_core_config/Config.h"
29 
30 namespace icl_core {
31 namespace logging {
32 
34 
35 LogOutputStream *SQLiteLogOutput::create(const icl_core::String& name, const icl_core::String& config_prefix,
36  icl_core::logging::LogLevel log_level)
37 {
38  return new SQLiteLogOutput(name, config_prefix, log_level);
39 }
40 
43  : LogOutputStream(name, config_prefix, log_level),
44  m_db(NULL)
45 {
46  icl_core::String db_filename = "";
47  if (!icl_core::config::get<icl_core::String>(config_prefix + "/FileName", db_filename))
48  {
49  std::cerr << "SQLite log output: No filename specified for SQLite log output stream "
50  << config_prefix << std::endl;
51  }
52 
53  bool rotate = false;
54  icl_core::config::get<bool>(config_prefix + "/Rotate", rotate);
55 
56  m_db = new SQLiteLogDb(db_filename, rotate);
57 }
58 
60 {
61  delete m_db;
62  m_db = NULL;
63 }
64 
66 {
67  m_db->openDatabase();
68 }
69 
70 void SQLiteLogOutput::pushImpl(const LogMessage& log_message)
71 {
72  m_db->writeLogLine("", log_message.timestamp.formatIso8601().c_str(), log_message.log_stream,
73  logLevelDescription(log_message.log_level), log_message.filename,
74  log_message.line, log_message.class_name, log_message.object_name,
75  log_message.function_name, log_message.message_text);
76 }
77 
79 {
81 }
82 
83 }
84 }
Contains icl_logging::SQLiteLogOutput.
char filename[cMAX_DESCRIPTION_LENGTH+1]
SQLiteLogOutput(const icl_core::String &name, const icl_core::String &config_prefix, icl_core::logging::LogLevel log_level)
virtual void pushImpl(const LogMessage &log_message)
Base header file for the configuration framework.
Defines logging macros.
#define REGISTER_LOG_OUTPUT_STREAM(name, factory)
bool get< bool >(const icl_core::String &key, bool &value)
Template specialization for boolean values.
Definition: Config.h:122
void writeLogLine(const char *app_id, const char *timestamp, const char *log_stream, const char *log_level, const char *filename, size_t line, const char *class_name, const char *object_name, const char *function_name, const char *message_text)
ThreadStream & endl(ThreadStream &stream)
Definition: ThreadStream.h:249
char object_name[cMAX_DESCRIPTION_LENGTH+1]
This is an output stream class for log messages.
std::string String
Definition: BaseTypes.h:43
char class_name[cMAX_IDENTIFIER_LENGTH+1]
char function_name[cMAX_IDENTIFIER_LENGTH+1]
char log_stream[cMAX_IDENTIFIER_LENGTH+1]
static LogOutputStream * create(const icl_core::String &name, const icl_core::String &config_prefix, icl_core::logging::LogLevel log_level=cDEFAULT_LOG_LEVEL)
const char * logLevelDescription(LogLevel log_level)
Definition: LogLevel.cpp:41
Defines an entry for the message queue.
String formatIso8601() const
Definition: TimeStamp.cpp:221


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58