plebble
thread_logger.h
Go to the documentation of this file.
1 /*
2 -------------------------------------------------------------------------------
3  PLEBBLE
4 -------------------------------------------------------------------------------
5  Copyright (C) 2019-2020 KATLAS Technology. (http://katlastechnology.com)
6  Copyright (C) 2017-2020 Marcos Mayorga. (mm@mm-studios.com)
7 
8  This file is part of our Plebble(R) Platform.
9 
10  The code below cannot be copied, used for any purpose other than the one
11  agreed and/or distributed without the express permission of
12  KATLAS Technology.
13 -------------------------------------------------------------------------------
14 
15 
16 */
17 #ifndef USGOV_bea2100f468b294b47083faa221c8529bb0e719ce9bb9c41938e5e7b9f2a8d7d
18 #define USGOV_bea2100f468b294b47083faa221c8529bb0e719ce9bb9c41938e5e7b9f2a8d7d
19 
20 #include <unordered_map>
21 #include <string>
22 #include <cassert>
23 #include <thread>
24 #include <mutex>
25 #include <fstream>
26 #include <chrono>
27 #include <sstream>
28 #include <sys/types.h>
29 #include <atomic>
30 #include <unistd.h>
31 #include "task.h"
32 #include <us/gov/config.h>
33 
34 namespace us { namespace dbg {
35  using namespace std;
36  using namespace chrono;
37 
38  struct thread_logger final:unordered_map<thread::id,task*> { //, ostream {
39 
44  const task& get_task() const;
45  void start(const string& dir, const string& n);
46  static void pstart(const string& n);
47 
48  template<typename... F>
49  void log(const string&log_level_, const string&log_class_, const F&... s) {
50  get_task().log(log_level_, log_class_, s...);
51  }
52 
53  template<typename O>
54  void logdump(const string&log_level_, const string&log_class_, const O& o) {
55  get_task().logdump(log_level_, log_class_, o);
56  }
57 
58  template<typename O>
59  void logdump(const string&log_level_, const string&log_class_, const string&prefix, const O& o) {
60  get_task().logdump(log_level_, log_class_, prefix, o);
61  }
62 
63  void log_stacktrace() const {
64  get_task().log_stacktrace();
65  }
66 
67  const string& get_logdir() const;
68  void thread_reused();
69  void log_info(ostream& os) const;
70  string ts() const;
71 
72  bool disabled{false};
73  uint64_t tsorig;
74  mutable mutex mx;
76  };
77 
78 
79 }}
80 
81 #endif
82 
us::dbg::thread_logger::pstart
static void pstart(const string &n)
task.h
us::dbg::thread_logger::logdump
void logdump(const string &log_level_, const string &log_class_, const O &o)
Definition: thread_logger.h:54
us::dbg::thread_logger::~thread_logger
~thread_logger()
us::dbg::thread_logger::log_info
void log_info(ostream &os) const
us::dbg::thread_logger::thread_reused
void thread_reused()
us::dbg::thread_logger::get_task
const task & get_task() const
thread_logger.h
us
Definition: daemon.h:22
us::dbg::thread_logger::log_stacktrace
void log_stacktrace() const
Definition: thread_logger.h:63
likely.h
us::dbg::thread_logger::start
void start(const string &dir, const string &n)
us::dbg::thread_logger::tsorig
uint64_t tsorig
Definition: thread_logger.h:73
us::dbg::thread_logger::log
void log(const string &log_level_, const string &log_class_, const F &... s)
Definition: thread_logger.h:49
us::dbg::thread_logger::new_task
task & new_task()
us::dbg::thread_logger::get_logdir
const string & get_logdir() const
log_info
#define log_info
Definition: gov.h:88
us::dbg::thread_logger::logdump
void logdump(const string &log_level_, const string &log_class_, const string &prefix, const O &o)
Definition: thread_logger.h:59
us::dbg
Definition: task.h:34
us::dbg::thread_logger::ts
string ts() const
us::dbg::task
Definition: task.h:40
us::dbg::thread_logger::thread_logger
thread_logger()
c
Definition: client.cpp:417
us::dbg::thread_logger
Definition: thread_logger.h:38
us::dbg::thread_logger::instance
static thread_logger instance
Definition: thread_logger.h:75
std
Definition: app.h:380
c
us::dbg::thread_logger c
Definition: thread_logger.cpp:26
config.h
us::dbg::thread_logger::get_task
task & get_task()
us::dbg::thread_logger::mx
mutex mx
Definition: thread_logger.h:74
LOGDIR
#define LOGDIR
Definition: config.h:12