mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-24 20:07:40 +02:00
logging
git-svn-id: svn://elaine/murooma/trunk@330 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
a51c000a2d
commit
abf70b4030
14 changed files with 166 additions and 168 deletions
|
@ -5,7 +5,7 @@
|
|||
Log::Log(std::string ident, int facility)
|
||||
{
|
||||
facility_ = facility;
|
||||
priority_ = LOG_DEBUG;
|
||||
priority_ = kLogDebug;
|
||||
strncpy(ident_, ident.c_str(), sizeof(ident_));
|
||||
ident_[sizeof(ident_)-1] = '\0';
|
||||
|
||||
|
@ -13,19 +13,6 @@ Log::Log(std::string ident, int facility)
|
|||
}
|
||||
|
||||
|
||||
std::string Log::LogPriorityToString(const LogPriority& priority)
|
||||
{
|
||||
switch(priority)
|
||||
{
|
||||
case kLog: return "dbg";
|
||||
case kOut: return "out";
|
||||
case kErr: return "err";
|
||||
default: return std::to_string((int)priority);
|
||||
}
|
||||
return std::to_string((int)priority);
|
||||
}
|
||||
|
||||
|
||||
std::string Log::Timestamp()
|
||||
{
|
||||
struct tm * dt;
|
||||
|
@ -41,15 +28,23 @@ int Log::sync()
|
|||
{
|
||||
if (buffer_.length())
|
||||
{
|
||||
// if (priority_ == kLog)
|
||||
// std::cout << Timestamp() << " [" << LogPriorityToString(priority_) << "] " << buffer_.c_str();
|
||||
// else
|
||||
if (priority_ == kDbg)
|
||||
#ifdef DEBUG_LOG
|
||||
std::cout << Timestamp() << " [dbg] " << buffer_.c_str() << std::flush;
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
else if (priority_ == kOut)
|
||||
std::cout << Timestamp() << " [out] " << buffer_.c_str() << std::flush;
|
||||
else if (priority_ == kErr)
|
||||
std::cerr << Timestamp() << " [err] " << buffer_.c_str() << std::flush;
|
||||
else
|
||||
{
|
||||
std::cout << Timestamp() << " [" << LogPriorityToString((LogPriority)priority_) << "] " << buffer_.c_str();
|
||||
std::cout << Timestamp() << " [" << std::to_string(priority_) << "] " << buffer_.c_str() << std::flush;
|
||||
syslog(priority_, "%s", buffer_.c_str());
|
||||
}
|
||||
buffer_.erase();
|
||||
priority_ = LOG_DEBUG; // default to debug for each message
|
||||
priority_ = kLogDebug; // default to debug for each message
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -60,6 +55,8 @@ int Log::overflow(int c)
|
|||
if (c != EOF)
|
||||
{
|
||||
buffer_ += static_cast<char>(c);
|
||||
if (c == '\n')
|
||||
sync();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -68,11 +65,10 @@ int Log::overflow(int c)
|
|||
return c;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority)
|
||||
{
|
||||
static_cast<Log *>(os.rdbuf())->priority_ = (int)log_priority;
|
||||
// if (log_priority == dbg)
|
||||
// os.flush();
|
||||
static_cast<Log*>(os.rdbuf())->priority_ = log_priority;
|
||||
return os;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue