MADARA  3.2.3
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  level_ = level;
47 }
48 
49 inline std::string
51 {
52  MADARA_GUARD_TYPE guard (mutex_);
53 
54  return tag_;
55 }
56 
57 inline void
59 {
60  MADARA_GUARD_TYPE guard (mutex_);
61 
62  tag_ = tag;
63 }
64 
65 inline int
67 {
68  return level_;
69 }
70 
71 inline void
73 {
74  MADARA_GUARD_TYPE guard (mutex_);
75 
76  this->term_added_ = true;
77 }
78 
79 inline void
81 {
82  MADARA_GUARD_TYPE guard (mutex_);
83 
84  this->syslog_added_ = true;
85 }
86 
87 inline void
89 {
90  MADARA_GUARD_TYPE guard (mutex_);
91 
92  this->term_added_ = false;
93  this->syslog_added_ = false;
94 
95  for (FileVectors::iterator i = files_.begin ();
96  i != files_.end (); ++i)
97  {
98  if (*i != stderr)
99  {
100  fclose (*i);
101  }
102  }
103 
104  files_.clear ();
105 }
106 
107 inline void
109 {
110  MADARA_GUARD_TYPE guard (mutex_);
111 
112  this->timestamp_format_ = format;
113 }
114 
115 #endif // _MADARA_LOGGER_LOGGER_INL_
std::atomic< int > level_
the maximum detail level for logging
Definition: Logger.h:178
std::string get_tag(void)
Gets the tag used for syslogs.
Definition: Logger.inl:50
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:66
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
static struct madara::knowledge::tags::string_t string
#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:80
void set_timestamp_format(const std::string &format="%x %X: ")
Sets timestamp format.
Definition: Logger.inl:108
void add_term(void)
Adds terminal to logger outputs.
Definition: Logger.inl:72
void clear(void)
Clears all log targets.
Definition: Logger.inl:88
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:58