icedb  version 0.5.1
Snow particle scattering database API
logging.cpp
Go to the documentation of this file.
1 #include "../icedb/logging.hpp"
2 #include <iostream>
3 #include <fstream>
4 #include <memory>
5 #include <sstream>
6 #include "../icedb/misc/os_functions.h"
7 namespace {
10  std::string logFile;
11  std::shared_ptr<std::ofstream> lOut;
13 }
14 namespace icedb {
15  namespace logging {
16  void emit_log(
17  const std::string &channel,
18  const std::string &message,
19  PRIORITIES p)
20  {
21  emit_log(channel.c_str(), message.c_str(), p);
22  }
24  void emit_log(
25  const char* channel,
26  const char* message,
27  PRIORITIES p)
28  {
29  if (logHandler) {
30  logHandler(channel, message, p);
31  }
32  else {
33  std::string m;
34  std::ostringstream out;
35  out << channel << " - " << message << std::endl;
36  m = out.str();
37  if (p >= logConsoleThreshold)
38  std::cerr << m;
39  if (p >= logDebugThreshold) {
40  ICEDB_writeDebugString(m.c_str());
41  }
42  if (lOut) {
43  *(lOut.get()) << m;
44  }
45  }
46  }
48  int argc,
49  char** argv,
50  const log_properties* lps) {
51  if (lps) {
54  logFile = lps->logFile;
55  if (logFile.size()) {
56  lOut = std::shared_ptr<std::ofstream>(new std::ofstream(logFile.c_str()));
57  }
58  }
59  }
60 
61  }
62 }
63 
std::shared_ptr< std::ofstream > lOut
Definition: logging.cpp:11
void register_log_handler(log_handler_ft p)
Definition: logging.cpp:23
icedb::logging::log_handler_ft logHandler
Definition: logging.cpp:12
void ICEDB_writeDebugString(const char *c)
void emit_log(const std::string &channel, const std::string &message, PRIORITIES p)
Definition: logging.cpp:16
void(* log_handler_ft)(const char *, const char *, PRIORITIES)
Definition: logging.hpp:27
void setupLogging(int argc, char **argv, const log_properties *lps)
Definition: logging.cpp:47