MADARA  3.4.1
Logger.inl
Go to the documentation of this file.
1 
2 #ifndef _MADARA_LOGGER_LOGGER_INL_
3 #define _MADARA_LOGGER_LOGGER_INL_
4 
5 #include "Logger.h"
6 #include <stdarg.h>
7 
8 #ifdef _MADARA_ANDROID_
9 #include <android/log.h>
10 #endif
11 
12 inline void madara::logger::Logger::add_file(const std::string& filename)
13 {
15  "Logger::add_file: attempting to open file %s\n", filename.c_str());
16 
17  if (filename != "")
18  {
19  FILE* new_file = fopen(filename.c_str(), "a+");
20 
21  if (new_file)
22  {
24  "Logger::add_file: opened file %s for logging\n", filename.c_str());
25 
26  MADARA_GUARD_TYPE guard(mutex_);
27 
28  files_.push_back(new_file);
29  }
30  else
31  {
33  "Logger::add_file: unable to open file %s for logging\n",
34  filename.c_str());
35  }
36  }
37 }
38 
39 inline void madara::logger::Logger::set_level(int level)
40 {
41  level_ = level;
42 }
43 
45 {
46  MADARA_GUARD_TYPE guard(mutex_);
47 
48  return tag_;
49 }
50 
51 #if 0
52 
54 {
55  return thread_level_;
56 }
57 
58 inline std::string madara::logger::Logger::get_thread_name(void)
59 {
60  return thread_name_;
61 }
62 
63 inline double madara::logger::Logger::get_thread_hertz(void)
64 {
65  return thread_hertz_;
66 }
67 
68 inline void madara::logger::Logger::set_thread_level(int level)
69 {
70  thread_level_ = level;
71 }
72 
73 inline void madara::logger::Logger::set_thread_name(const std::string name)
74 {
75  thread_name_ = name;
76 }
77 
78 inline void madara::logger::Logger::set_thread_hertz(double hertz)
79 {
80  thread_hertz_ = hertz;
81 }
82 
83 #else
84 
86 {
87  return -1;
88 }
89 
90 #endif
91 
93 {
94  MADARA_GUARD_TYPE guard(mutex_);
95 
96  tag_ = tag;
97 }
98 
100 {
101  return level_;
102 }
103 
105 {
106  MADARA_GUARD_TYPE guard(mutex_);
107 
108  this->term_added_ = true;
109 }
110 
112 {
113  MADARA_GUARD_TYPE guard(mutex_);
114 
115  this->syslog_added_ = true;
116 }
117 
119 {
120  MADARA_GUARD_TYPE guard(mutex_);
121 
122  this->term_added_ = false;
123  this->syslog_added_ = false;
124 
125  for (FileVectors::iterator i = files_.begin(); i != files_.end(); ++i)
126  {
127  if (*i != stderr)
128  {
129  fclose(*i);
130  }
131  }
132 
133  files_.clear();
134 }
135 
137  const std::string& format)
138 {
139  MADARA_GUARD_TYPE guard(mutex_);
140 
141  this->timestamp_format_ = format;
142 }
143 
144 #endif // _MADARA_LOGGER_LOGGER_INL_
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:41
static int get_thread_level(void)
Fetches thread local storage value for thread level.
Definition: Logger.inl:85
int get_level(void)
Gets the maximum logging detail level.
Definition: Logger.inl:99
void add_file(const std::string &filename)
Adds a file to the logger.
Definition: Logger.inl:12
void add_term(void)
Adds terminal to logger outputs.
Definition: Logger.inl:104
void set_tag(const std::string &tag)
Sets the tag used for syslogs (e.g.
Definition: Logger.inl:92
void set_timestamp_format(const std::string &format="%x %X: ")
Sets timestamp format.
Definition: Logger.inl:136
MADARA_LOCK_TYPE mutex_
mutex for changes
Definition: Logger.h:311
void clear(void)
Clears all log targets.
Definition: Logger.inl:118
void add_syslog(void)
Adds the system log.
Definition: Logger.inl:111
FileVectors files_
list of all log outputs
Definition: Logger.h:314
std::string get_tag(void)
Gets the tag used for syslogs.
Definition: Logger.inl:44
void set_level(int level)
Sets the maximum logging detail level.
Definition: Logger.inl:39
constexpr string_t string