Browse Source

Fixed bug #148 Custom 'syslog.id' and openlog - invalid API use

master
Artyom Beilis 7 years ago
parent
commit
b6dcd8c632
3 changed files with 32 additions and 5 deletions
  1. +9
    -0
      booster/booster/log.h
  2. +21
    -2
      booster/lib/log/src/log.cpp
  3. +2
    -3
      src/service.cpp

+ 9
- 0
booster/booster/log.h View File

@@ -362,6 +362,15 @@ namespace log {
/// to provide non-default parameters, you need to call it on your own
///
syslog();

///
/// Create a new logger and call openlog with id, opts and facility
///
syslog(std::string const &id,int opts,int facility = 0);
///
/// Create a new logger and call openlog with NULL id , opts and facility
///
syslog(int opts,int facility = 0);
///
/// Send the message to the log
///


+ 21
- 2
booster/lib/log/src/log.cpp View File

@@ -419,12 +419,31 @@ namespace log {
d->stream << format_plain_text_message_tz(msg,tz_offset_) << std::endl;
}
#ifdef BOOSTER_POSIX
struct syslog::data {};
syslog::syslog()
struct syslog::data {
std::string id;
bool log_was_opened;
data() : log_was_opened(false) {}
};
syslog::syslog(int opts,int facility) :
d(new data())
{
d->log_was_opened = true;
openlog(NULL,opts,facility);
}
syslog::syslog(std::string const &id,int opts,int facility) :
d(new data())
{
d->id = id;
d->log_was_opened = true;
openlog(d->id.c_str(),opts,facility);
}
syslog::syslog() : d(new data())
{
}
syslog::~syslog()
{
if(d.get() && d->log_was_opened)
closelog();
}
void syslog::log(message const &msg)
{


+ 2
- 3
src/service.cpp View File

@@ -276,10 +276,9 @@ void impl::setup_logging(json::value const &settings)
else if(op=="LOG_PID") ops|=LOG_PID;
}
if(id.empty())
::openlog(0,ops,0);
logger::instance().add_sink(booster::shared_ptr<sink>(new sinks::syslog(ops)));
else
::openlog(id.c_str(),ops,0);
logger::instance().add_sink(booster::shared_ptr<sink>(new sinks::syslog()));
logger::instance().add_sink(booster::shared_ptr<sink>(new sinks::syslog(id,ops)));
#endif
}



Loading…
Cancel
Save