update logger

This commit is contained in:
badaix 2017-09-12 21:19:18 +02:00
parent 0c3a881df0
commit 756453f9d2
9 changed files with 44 additions and 37 deletions

View file

@ -162,7 +162,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder
{ {
if (buffer[channel] == NULL) if (buffer[channel] == NULL)
{ {
SLOG(LOG_ERR) << "ERROR: buffer[" << channel << "] is NULL\n"; SLOG(ERROR) << "ERROR: buffer[" << channel << "] is NULL\n";
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
} }
@ -210,7 +210,7 @@ void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMet
void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
{ {
(void)decoder, (void)client_data; (void)decoder, (void)client_data;
SLOG(LOG_ERR) << "Got error callback: " << FLAC__StreamDecoderErrorStatusString[status] << "\n"; SLOG(ERROR) << "Got error callback: " << FLAC__StreamDecoderErrorStatusString[status] << "\n";
static_cast<FlacDecoder*>(client_data)->lastError_ = std::unique_ptr<FLAC__StreamDecoderErrorStatus>(new FLAC__StreamDecoderErrorStatus(status)); static_cast<FlacDecoder*>(client_data)->lastError_ = std::unique_ptr<FLAC__StreamDecoderErrorStatus>(new FLAC__StreamDecoderErrorStatus(status));
/// TODO, see issue #120: /// TODO, see issue #120:

View file

@ -194,7 +194,7 @@ int main (int argc, char **argv)
processPriority = 19; processPriority = 19;
if (processPriority != 0) if (processPriority != 0)
setpriority(PRIO_PROCESS, 0, processPriority); setpriority(PRIO_PROCESS, 0, processPriority);
SLOG(LOG_NOTICE) << "daemon started" << std::endl; SLOG(NOTICE) << "daemon started" << std::endl;
} }
#endif #endif
@ -226,7 +226,7 @@ int main (int argc, char **argv)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
SLOG(LOG_ERR) << "Exception: " << e.what() << std::endl; SLOG(ERROR) << "Exception: " << e.what() << std::endl;
} }
chronos::sleep(500); chronos::sleep(500);
} }
@ -245,11 +245,11 @@ int main (int argc, char **argv)
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
SLOG(LOG_ERR) << "Exception: " << e.what() << std::endl; SLOG(ERROR) << "Exception: " << e.what() << std::endl;
exitcode = EXIT_FAILURE; exitcode = EXIT_FAILURE;
} }
SLOG(LOG_NOTICE) << "daemon terminated." << endl; SLOG(NOTICE) << "daemon terminated." << endl;
exit(exitcode); exit(exitcode);
} }

View file

@ -3,7 +3,7 @@
/ _\ ( )( \/ )( ) / \ / __) / _\ ( )( \/ )( ) / \ / __)
/ \ )( ) ( / (_/\( O )( (_ \ / \ )( ) ( / (_/\( O )( (_ \
\_/\_/(__)(_/\_)\____/ \__/ \___/ \_/\_/(__)(_/\_)\____/ \__/ \___/
version 0.13.0 version 0.16.0
https://github.com/badaix/aixlog https://github.com/badaix/aixlog
This file is part of aixlog This file is part of aixlog
@ -47,20 +47,26 @@
#endif #endif
/// Internal helper defines /// Internal helper macros (exposed, but shouldn't be used directly)
#define LOG_WO_TAG(P) std::clog << (AixLog::Severity)P #define AIXLOG_INTERNAL__LOG_WO_TAG(SEVERITY_) std::clog << (AixLog::Severity)AixLog::SEVERITY_
#define LOG_TAG(P, T) std::clog << (AixLog::Severity)P << TAG(T) #define AIXLOG_INTERNAL__LOG_TAG(SEVERITY_, TAG_) std::clog << (AixLog::Severity)AixLog::SEVERITY_ << TAG(TAG_)
#define ONE_COLOR(FG) AixLog::Color::FG #define AIXLOG_INTERNAL__ONE_COLOR(FG_) AixLog::Color::FG_
#define TWO_COLOR(FG, BG) AixLog::TextColor(AixLog::Color::FG, AixLog::Color::BG) #define AIXLOG_INTERNAL__TWO_COLOR(FG_, BG_) AixLog::TextColor(AixLog::Color::FG_, AixLog::Color::BG_)
#define VAR_PARM(x,P,T,FUN, ...) FUN //https://stackoverflow.com/questions/3046889/optional-parameters-with-c-macros
#define AIXLOG_INTERNAL__VAR_PARM(x,PARAM1_,PARAM2_,FUNC_, ...) FUNC_
/// External logger defines /// External logger macros
#define LOG(...) VAR_PARM(,##__VA_ARGS__, LOG_TAG(__VA_ARGS__), LOG_WO_TAG(__VA_ARGS__)) << TIMESTAMP << FUNC // usage: LOG(SEVERITY) or LOG(SEVERITY, TAG)
#define SLOG(...) VAR_PARM(,##__VA_ARGS__, LOG_TAG(__VA_ARGS__), LOG_WO_TAG(__VA_ARGS__)) << TIMESTAMP << SPECIAL << FUNC // e.g.: LOG(NOTICE) or LOG(NOTICE, "my tag")
#define COLOR(...) VAR_PARM(,##__VA_ARGS__, TWO_COLOR(__VA_ARGS__), ONE_COLOR(__VA_ARGS__)) #define LOG(...) AIXLOG_INTERNAL__VAR_PARM(,##__VA_ARGS__, AIXLOG_INTERNAL__LOG_TAG(__VA_ARGS__), AIXLOG_INTERNAL__LOG_WO_TAG(__VA_ARGS__)) << TIMESTAMP << FUNC
#define SLOG(...) AIXLOG_INTERNAL__VAR_PARM(,##__VA_ARGS__, AIXLOG_INTERNAL__LOG_TAG(__VA_ARGS__), AIXLOG_INTERNAL__LOG_WO_TAG(__VA_ARGS__)) << TIMESTAMP << SPECIAL << FUNC
// usage: COLOR(TEXT_COLOR, BACKGROUND_COLOR) or COLOR(TEXT_COLOR)
// e.g.: COLOR(yellow, blue) or COLOR(red)
#define COLOR(...) AIXLOG_INTERNAL__VAR_PARM(,##__VA_ARGS__, AIXLOG_INTERNAL__TWO_COLOR(__VA_ARGS__), AIXLOG_INTERNAL__ONE_COLOR(__VA_ARGS__))
#define FUNC AixLog::Function(__func__, __FILE__, __LINE__) #define FUNC AixLog::Function(__func__, __FILE__, __LINE__)
#define TAG AixLog::Tag #define TAG AixLog::Tag
@ -69,6 +75,10 @@
#define TIMESTAMP AixLog::Timestamp(std::chrono::system_clock::now()) #define TIMESTAMP AixLog::Timestamp(std::chrono::system_clock::now())
namespace AixLog
{
enum SEVERITY enum SEVERITY
{ {
// https://chromium.googlesource.com/chromium/mini_chromium/+/master/base/logging.cc // https://chromium.googlesource.com/chromium/mini_chromium/+/master/base/logging.cc
@ -98,9 +108,6 @@ enum SEVERITY
namespace AixLog
{
enum class Type enum class Type
{ {
normal, normal,
@ -557,7 +564,7 @@ struct SinkCerr : public SinkFormat
/// Not tested due to unavailability of Windows /// Not tested due to unavailability of Windows
struct SinkOutputDebugString : Sink struct SinkOutputDebugString : public Sink
{ {
SinkOutputDebugString(Severity severity, Type type = Type::all, const std::string& default_tag = "") : Sink(severity, type) SinkOutputDebugString(Severity severity, Type type = Type::all, const std::string& default_tag = "") : Sink(severity, type)
{ {
@ -573,7 +580,7 @@ struct SinkOutputDebugString : Sink
struct SinkUnifiedLogging : Sink struct SinkUnifiedLogging : public Sink
{ {
SinkUnifiedLogging(Severity severity, Type type = Type::all) : Sink(severity, type) SinkUnifiedLogging(Severity severity, Type type = Type::all) : Sink(severity, type)
{ {
@ -918,7 +925,7 @@ static std::ostream& operator<< (std::ostream& os, const Color& color)
} }
} } /// namespace AixLog
#endif /// AIX_LOG_HPP #endif /// AIX_LOG_HPP

View file

@ -48,7 +48,7 @@ Config::Config()
throw SnapException("failed to create settings directory: \"" + dir + "\": " + cpt::to_string(errno)); throw SnapException("failed to create settings directory: \"" + dir + "\": " + cpt::to_string(errno));
filename_ = dir + "server.json"; filename_ = dir + "server.json";
SLOG(LOG_NOTICE) << "Settings file: \"" << filename_ << "\"\n"; SLOG(NOTICE) << "Settings file: \"" << filename_ << "\"\n";
int fd; int fd;
if ((fd = open(filename_.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) if ((fd = open(filename_.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)

View file

@ -48,7 +48,7 @@ void ControlServer::cleanup()
{ {
if (!(*it)->active()) if (!(*it)->active())
{ {
SLOG(LOG_ERR) << "Session inactive. Removing\n"; SLOG(ERROR) << "Session inactive. Removing\n";
// don't block: remove ClientSession in a thread // don't block: remove ClientSession in a thread
auto func = [](shared_ptr<ControlSession> s)->void{s->stop();}; auto func = [](shared_ptr<ControlSession> s)->void{s->stop();};
std::thread t(func, *it); std::thread t(func, *it);
@ -115,7 +115,7 @@ void ControlServer::handleAccept(socket_ptr socket)
setsockopt(socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); setsockopt(socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); setsockopt(socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
// socket->set_option(boost::asio::ip::tcp::no_delay(false)); // socket->set_option(boost::asio::ip::tcp::no_delay(false));
SLOG(LOG_NOTICE) << "ControlServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl; SLOG(NOTICE) << "ControlServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl;
shared_ptr<ControlSession> session = make_shared<ControlSession>(this, socket); shared_ptr<ControlSession> session = make_shared<ControlSession>(this, socket);
{ {
std::lock_guard<std::recursive_mutex> mlock(mutex_); std::lock_guard<std::recursive_mutex> mlock(mutex_);

View file

@ -145,7 +145,7 @@ void ControlSession::reader()
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
SLOG(LOG_ERR) << "Exception in ControlSession::reader(): " << e.what() << endl; SLOG(ERROR) << "Exception in ControlSession::reader(): " << e.what() << endl;
} }
active_ = false; active_ = false;
} }
@ -166,7 +166,7 @@ void ControlSession::writer()
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
SLOG(LOG_ERR) << "Exception in ControlSession::writer(): " << e.what() << endl; SLOG(ERROR) << "Exception in ControlSession::writer(): " << e.what() << endl;
} }
active_ = false; active_ = false;
} }

View file

@ -99,7 +99,7 @@ int main(int argc, char* argv[])
} }
catch (const std::invalid_argument& e) catch (const std::invalid_argument& e)
{ {
SLOG(LOG_ERR) << "Exception: " << e.what() << std::endl; SLOG(ERROR) << "Exception: " << e.what() << std::endl;
cout << "\n" << op << "\n"; cout << "\n" << op << "\n";
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -180,7 +180,7 @@ int main(int argc, char* argv[])
processPriority = 19; processPriority = 19;
if (processPriority != 0) if (processPriority != 0)
setpriority(PRIO_PROCESS, 0, processPriority); setpriority(PRIO_PROCESS, 0, processPriority);
SLOG(LOG_NOTICE) << "daemon started" << std::endl; SLOG(NOTICE) << "daemon started" << std::endl;
} }
#endif #endif
@ -214,11 +214,11 @@ int main(int argc, char* argv[])
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
SLOG(LOG_ERR) << "Exception: " << e.what() << std::endl; SLOG(ERROR) << "Exception: " << e.what() << std::endl;
exitcode = EXIT_FAILURE; exitcode = EXIT_FAILURE;
} }
SLOG(LOG_NOTICE) << "daemon terminated." << endl; SLOG(NOTICE) << "daemon terminated." << endl;
exit(exitcode); exit(exitcode);
} }

View file

@ -585,7 +585,7 @@ void StreamServer::handleAccept(socket_ptr socket)
/// experimental: turn on tcp::no_delay /// experimental: turn on tcp::no_delay
socket->set_option(tcp::no_delay(true)); socket->set_option(tcp::no_delay(true));
SLOG(LOG_NOTICE) << "StreamServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl; SLOG(NOTICE) << "StreamServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl;
shared_ptr<StreamSession> session = make_shared<StreamSession>(this, socket); shared_ptr<StreamSession> session = make_shared<StreamSession>(this, socket);
session->setBufferMs(settings_.bufferMs); session->setBufferMs(settings_.bufferMs);
@ -620,7 +620,7 @@ void StreamServer::start()
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
SLOG(LOG_NOTICE) << "StreamServer::start: " << e.what() << endl; SLOG(NOTICE) << "StreamServer::start: " << e.what() << endl;
stop(); stop();
throw; throw;
} }

View file

@ -183,7 +183,7 @@ void StreamSession::getNextMessage()
baseMessage.deserialize(&buffer[0]); baseMessage.deserialize(&buffer[0]);
if (baseMessage.size > msg::max_size) if (baseMessage.size > msg::max_size)
{ {
SLOG(LOG_ERR) << "received message of type " << baseMessage.type << " to large: " << baseMessage.size << "\n"; SLOG(ERROR) << "received message of type " << baseMessage.type << " to large: " << baseMessage.size << "\n";
stop(); stop();
return; return;
} }
@ -213,7 +213,7 @@ void StreamSession::reader()
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
SLOG(LOG_ERR) << "Exception in StreamSession::reader(): " << e.what() << endl; SLOG(ERROR) << "Exception in StreamSession::reader(): " << e.what() << endl;
} }
if (active_ && (messageReceiver_ != NULL)) if (active_ && (messageReceiver_ != NULL))
@ -252,7 +252,7 @@ void StreamSession::writer()
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
SLOG(LOG_ERR) << "Exception in StreamSession::writer(): " << e.what() << endl; SLOG(ERROR) << "Exception in StreamSession::writer(): " << e.what() << endl;
} }
if (active_ && (messageReceiver_ != NULL)) if (active_ && (messageReceiver_ != NULL))