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)
{
SLOG(LOG_ERR) << "ERROR: buffer[" << channel << "] is NULL\n";
SLOG(ERROR) << "ERROR: buffer[" << channel << "] is NULL\n";
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)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));
/// TODO, see issue #120:

View file

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

View file

@ -3,7 +3,7 @@
/ _\ ( )( \/ )( ) / \ / __)
/ \ )( ) ( / (_/\( O )( (_ \
\_/\_/(__)(_/\_)\____/ \__/ \___/
version 0.13.0
version 0.16.0
https://github.com/badaix/aixlog
This file is part of aixlog
@ -47,20 +47,26 @@
#endif
/// Internal helper defines
#define LOG_WO_TAG(P) std::clog << (AixLog::Severity)P
#define LOG_TAG(P, T) std::clog << (AixLog::Severity)P << TAG(T)
/// Internal helper macros (exposed, but shouldn't be used directly)
#define AIXLOG_INTERNAL__LOG_WO_TAG(SEVERITY_) std::clog << (AixLog::Severity)AixLog::SEVERITY_
#define AIXLOG_INTERNAL__LOG_TAG(SEVERITY_, TAG_) std::clog << (AixLog::Severity)AixLog::SEVERITY_ << TAG(TAG_)
#define ONE_COLOR(FG) AixLog::Color::FG
#define TWO_COLOR(FG, BG) AixLog::TextColor(AixLog::Color::FG, AixLog::Color::BG)
#define AIXLOG_INTERNAL__ONE_COLOR(FG_) AixLog::Color::FG_
#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
#define LOG(...) VAR_PARM(,##__VA_ARGS__, LOG_TAG(__VA_ARGS__), LOG_WO_TAG(__VA_ARGS__)) << TIMESTAMP << FUNC
#define SLOG(...) VAR_PARM(,##__VA_ARGS__, LOG_TAG(__VA_ARGS__), LOG_WO_TAG(__VA_ARGS__)) << TIMESTAMP << SPECIAL << FUNC
#define COLOR(...) VAR_PARM(,##__VA_ARGS__, TWO_COLOR(__VA_ARGS__), ONE_COLOR(__VA_ARGS__))
/// External logger macros
// usage: LOG(SEVERITY) or LOG(SEVERITY, TAG)
// e.g.: LOG(NOTICE) or LOG(NOTICE, "my tag")
#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 TAG AixLog::Tag
@ -69,6 +75,10 @@
#define TIMESTAMP AixLog::Timestamp(std::chrono::system_clock::now())
namespace AixLog
{
enum SEVERITY
{
// https://chromium.googlesource.com/chromium/mini_chromium/+/master/base/logging.cc
@ -98,9 +108,6 @@ enum SEVERITY
namespace AixLog
{
enum class Type
{
normal,
@ -557,7 +564,7 @@ struct SinkCerr : public SinkFormat
/// 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)
{
@ -573,7 +580,7 @@ struct SinkOutputDebugString : Sink
struct SinkUnifiedLogging : Sink
struct SinkUnifiedLogging : public Sink
{
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

View file

@ -48,7 +48,7 @@ Config::Config()
throw SnapException("failed to create settings directory: \"" + dir + "\": " + cpt::to_string(errno));
filename_ = dir + "server.json";
SLOG(LOG_NOTICE) << "Settings file: \"" << filename_ << "\"\n";
SLOG(NOTICE) << "Settings file: \"" << filename_ << "\"\n";
int fd;
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())
{
SLOG(LOG_ERR) << "Session inactive. Removing\n";
SLOG(ERROR) << "Session inactive. Removing\n";
// don't block: remove ClientSession in a thread
auto func = [](shared_ptr<ControlSession> s)->void{s->stop();};
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_SNDTIMEO, &tv, sizeof(tv));
// 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);
{
std::lock_guard<std::recursive_mutex> mlock(mutex_);

View file

@ -145,7 +145,7 @@ void ControlSession::reader()
}
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;
}
@ -166,7 +166,7 @@ void ControlSession::writer()
}
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;
}

View file

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

View file

@ -585,7 +585,7 @@ void StreamServer::handleAccept(socket_ptr socket)
/// experimental: turn on tcp::no_delay
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);
session->setBufferMs(settings_.bufferMs);
@ -620,7 +620,7 @@ void StreamServer::start()
}
catch (const std::exception& e)
{
SLOG(LOG_NOTICE) << "StreamServer::start: " << e.what() << endl;
SLOG(NOTICE) << "StreamServer::start: " << e.what() << endl;
stop();
throw;
}

View file

@ -183,7 +183,7 @@ void StreamSession::getNextMessage()
baseMessage.deserialize(&buffer[0]);
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();
return;
}
@ -213,7 +213,7 @@ void StreamSession::reader()
}
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))
@ -252,7 +252,7 @@ void StreamSession::writer()
}
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))