alaCarte Maps
Renderer for OpenStreetMap tiles
parser_logger.cpp
Go to the documentation of this file.
1 
24 
25 
33 ParserLogger::LogStream::LogStream( const shared_ptr<ParserLogger>& logger, Category cat )
34  : logger(logger)
35  , category(cat)
36 {
37 
38 }
39 
47  : logger(other.logger)
48  , category(other.category)
49 
50 {
51 }
52 
58 {
59  if(!value.str().empty())
60  {
61  logger->logToStream(category, logvalue());
62  }
63 }
64 
70 {
71  return value.str();
72 }
73 
80 ParserLogger::ParserLogger(const string& parsedFile)
81  : filename(parsedFile + ".error")
82 {
83 
84 }
85 
86 
93 {
94  return LogStream(this->shared_from_this(), Warning);
95 }
96 
103 {
104  return LogStream(this->shared_from_this(), Error);
105 }
106 
111 void ParserLogger::error(const string& str)
112 {
113  logToStream(Error, str);
114 }
115 
120 void ParserLogger::warn(const string& str)
121 {
122  logToStream(Warning, str);
123 }
124 
132 void ParserLogger::logToStream(Category cat, const string& str )
133 {
134  if(str.empty())
135  return;
136 
137  if(!outputStream.is_open() && filename.size())
138  {
139  outputStream.open(filename.c_str());
140 
141  if(!outputStream.is_open())
142  {
143  LOG_SEV(style_log, fatal) << "Failed to open \"" + filename + "\"";
144  filename.clear();
145  return;
146  }
147  }
148 
149  switch (cat)
150  {
152  outputStream << "Waring: " << str << "\n";
153  LOG_SEV(style_log, warning) << str;
154  break;
155  default:
156  case ParserLogger::Error:
157  outputStream << "Error: " << str << "\n";
158  LOG_SEV(style_log, error) << str;
159  break;
160  }
161 
162  outputStream.flush();
163 }
164 
string logvalue() const
Returns the log value.
~LogStream()
Destroyes the log stream.
LogStream(const shared_ptr< ParserLogger > &logger, Category cat)
This file is part of alaCarte.
#define LOG_SEV(log, lvl)
Definition: settings.hpp:78
LogStream warnStream()
Returns a warn stream.
LogStream errorStream()
Returns a error stream.
void logToStream(Category cat, const string &str)
prints a message to the log
std::ofstream outputStream
std::ostringstream value
void warn(const string &str)
outputs an warn message
ParserLogger(const string &parsedFile)
Creates a new parse logger.
shared_ptr< ParserLogger > logger
void error(const string &str)
outputs an error message