MADARA  3.1.8
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 
13 inline void
15 {
17  "Logger::add_file: attempting to open file %s\n",
18  filename.c_str ());
19 
20  if (filename != "")
21  {
22  FILE * new_file = fopen (filename.c_str (), "a+");
23 
24  if (new_file)
25  {
27  "Logger::add_file: opened file %s for logging\n",
28  filename.c_str ());
29 
30  MADARA_GUARD_TYPE guard (mutex_);
31 
32  files_.push_back (new_file);
33  }
34  else
35  {
37  "Logger::add_file: unable to open file %s for logging\n",
38  filename.c_str ());
39  }
40  }
41 }
42 
43 inline void
45 {
46  MADARA_GUARD_TYPE guard (mutex_);
47 
48  level_ = level;
49 }
50 
51 inline std::string
53 {
54  MADARA_GUARD_TYPE guard (mutex_);
55 
56  return tag_;
57 }
58 
59 inline void
61 {
62  MADARA_GUARD_TYPE guard (mutex_);
63 
64  tag_ = tag;
65 }
66 
67 inline int
69 {
70  MADARA_GUARD_TYPE guard (mutex_);
71 
72  return level_;
73 }
74 
75 inline void
77 {
78  MADARA_GUARD_TYPE guard (mutex_);
79 
80  this->term_added_ = true;
81 }
82 
83 inline void
85 {
86  MADARA_GUARD_TYPE guard (mutex_);
87 
88  this->syslog_added_ = true;
89 }
90 
91 inline void
93 {
94  MADARA_GUARD_TYPE guard (mutex_);
95 
96  this->term_added_ = false;
97  this->syslog_added_ = false;
98 
99  for (FileVectors::iterator i = files_.begin ();
100  i != files_.end (); ++i)
101  {
102  if (*i != stderr)
103  {
104  fclose (*i);
105  }
106  }
107 
108  files_.clear ();
109 }
110 
111 inline void
113 {
114  MADARA_GUARD_TYPE guard (mutex_);
115 
116  this->timestamp_format_ = format;
117 }
118 
119 #endif // _MADARA_LOGGER_LOGGER_INL_
std::string get_tag(void)
Gets the tag used for syslogs.
Definition: Logger.inl:52
int level_
the maximum detail level for logging
Definition: Logger.h:178
std::string timestamp_format_
the timestamp format. Default is "" for no timestamp
Definition: Logger.h:190
void set_level(int level)
Sets the maximum logging detail level.
Definition: Logger.inl:44
bool term_added_
tracks whether terminal output has been added
Definition: Logger.h:181
int get_level(void)
Gets the maximum logging detail level.
Definition: Logger.inl:68
FileVectors files_
list of all log outputs
Definition: Logger.h:175
bool syslog_added_
tracks whether the system log has been added
Definition: Logger.h:184
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:32
void add_file(const std::string &filename)
Adds a file to the logger.
Definition: Logger.inl:14
void add_syslog(void)
Adds the system log.
Definition: Logger.inl:84
static constexpr struct madara::knowledge::tags::string_t string
void set_timestamp_format(const std::string &format="%x %X: ")
Sets timestamp format.
Definition: Logger.inl:112
void add_term(void)
Adds terminal to logger outputs.
Definition: Logger.inl:76
void clear(void)
Clears all log targets.
Definition: Logger.inl:92
MADARA_LOCK_TYPE mutex_
mutex for changes
Definition: Logger.h:172
std::string tag_
the tag used for logging to system logs
Definition: Logger.h:187
void set_tag(const std::string &tag)
Sets the tag used for syslogs (e.g.
Definition: Logger.inl:60