28#include <zypp-core/zyppng/io/Socket>
29#include <zypp-core/zyppng/io/SockAddr>
30#include <zypp-core/zyppng/base/EventLoop>
31#include <zypp-core/zyppng/base/EventDispatcher>
32#include <zypp-core/zyppng/base/Timer>
34#include <zypp-core/zyppng/thread/Wakeup>
36#include <zypp-core/zyppng/base/SocketNotifier>
72 std::this_thread::yield();
113 if (
_thread.get_id() != std::this_thread::get_id() )
132 _thread = std::thread( [
this] () {
148 std::vector<zyppng::Socket::Ptr>
clients;
151 server->bind( std::make_shared<zyppng::UnixSockAddr>(
sockPath(),
true ) );
164 auto writer = getLineWriter();
165 if ( !writer ) return;
166 while ( sock->canReadLine() ) {
167 auto br = sock->readLine();
168 writer->writeOut( std::string( br.data(), br.size() - 1 ) );
174 auto lock =
sock.lock();
178 auto idx = std::find_if(
clients.begin(),
clients.end(), [lock](
const auto &
s ){ return lock.get() == s.get(); } );
193 for (
auto &sock : clients ){
194 auto br = sock->readLine();
195 while ( !br.empty() ) {
196 if ( br.back () ==
'\n' )
197 writer->writeOut( std::string( br.data(), br.size() - 1 ) );
199 writer->writeOut( std::string( br.data(), br.size() ) );
201 br = sock->readLine();
224 LogThread::instance();
254 if ( inPushMessage ) {
262 inPushMessage =
true;
265 if ( std::this_thread::get_id() == LogThread::instance().threadId() ) {
266 auto writer = LogThread::instance().getLineWriter();
272 if(!ensureConnection())
275 if ( msg.back() !=
'\n' )
279 while (
written < msg.size() ) {
293 bool inPushMessage =
false;
308 static constexpr std::string_view
OO {
"\033[0m" };
309 static constexpr std::string_view
WH {
"\033[37;40m" };
310 static constexpr std::string_view
CY {
"\033[36;40m" };
311 static constexpr std::string_view
YE {
"\033[33;1;40m" };
312 static constexpr std::string_view
GR {
"\033[32;40m" };
313 static constexpr std::string_view
RE {
"\033[31;1;40m" };
314 static constexpr std::string_view
MA {
"\033[35;40m" };
316 unsigned TraceLeave::_depth = 0;
331 unsigned depth =
_depth++;
338 unsigned depth = --
_depth;
344 : _strout {
std::cerr }
389 std::ofstream *
fstr = 0;
390 _outs.reset( (
fstr =
new std::ofstream(
file_r.asString().c_str(), std::ios_base::app )) );
391 fstr->rdbuf()->pubsetbuf(0,0);
449 std::streamsize
xsputn(
const char *
s, std::streamsize
n )
override
469 for (
int i = 0;
i <
n; ++
i, ++
c )
587 return impl ?
impl->hideThreadName() :
false;
600 return impl ?
impl->_logToPPIDMode :
false;
667 ret <<
"---<RESET LOGSTREAM FROM FAILED STATE]" << endl;
700 if (
getenv(
"ZYPP_LOGFILE") )
703 if (
getenv(
"ZYPP_PROFILING") )
760 return str <<
"LogControlImpl";
809 return impl->isExcessive();
816 using logger::LogControlImpl;
828 static char hostname[1024];
830 std::string now(
Date::now().form(
"%Y-%m-%d %H:%M:%S" ) );
843 ret =
str::form(
"%s <%d> %s(%d) [%s] %s(%s):%d {T:%s} %s",
886 return impl->getLineWriter();
951 impl->excessive(
true );
958 impl->excessive(
false );
std::once_flag flagReadEnvAutomatically
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void reset()
Reset to default Ctor values.
static Date now()
Return the current time.
LogClient(LogClient &&)=delete
LogClient(const LogClient &)=delete
LogClient & operator=(const LogClient &)=delete
LogClient & operator=(LogClient &&)=delete
void pushMessage(std::string msg)
shared_ptr< log::LineWriter > _lineWriter
LogThread & operator=(const LogThread &)=delete
zypp::shared_ptr< log::LineWriter > getLineWriter()
zyppng::Wakeup _stopSignal
LogThread(const LogThread &)=delete
std::thread::id threadId()
LogThread(LogThread &&)=delete
LogThread & operator=(LogThread &&)=delete
void setLineWriter(zypp::shared_ptr< log::LineWriter > writer)
static LogThread & instance()
static std::string sockPath()
std::atomic_flag _atomicLock
Maintain logfile related options.
friend std::ostream & operator<<(std::ostream &str, const LogControl &obj)
shared_ptr< LineWriter > getLineWriter() const
Get the current LineWriter.
void setLineWriter(const shared_ptr< LineWriter > &writer_r)
Assign a LineWriter.
void emergencyShutdown()
will cause the log thread to exit and flush all sockets
void logToStdErr()
Log to std::err.
void logRawLine(std::string &&line)
will push a line to the logthread without formatting it
void logNothing()
Turn off logging.
static void notifyFork()
This will completely disable logging.
void setLineFormater(const shared_ptr< LineFormater > &formater_r)
Assign a LineFormater.
void enableLogForwardingMode(bool enable=true)
void logfile(const Pathname &logfile_r)
Set path for the logfile.
int overflow(int ch=EOF) override
std::streamsize xsputn(const char *s, std::streamsize n) override
Loglinebuf(const Loglinebuf &)=default
Loglinebuf(std::string group_r, LogLevel level_r)
Loglinebuf(Loglinebuf &&)=default
Loglinebuf & operator=(const Loglinebuf &)=default
void tagSet(const char *fil_r, const char *fnc_r, int lne_r)
virtual int writeout(const char *s, std::streamsize n)
Loglinebuf & operator=(Loglinebuf &&)=default
Loglinestream(const std::string &group_r, LogLevel level_r)
Loglinestream(const Loglinestream &)=delete
Loglinestream & operator=(const Loglinestream &)=delete
std::ostream & getStream(const char *fil_r, const char *fnc_r, int lne_r)
Loglinestream(Loglinestream &&)=delete
Loglinestream & operator=(Loglinestream &&)=delete
SignalProxy< void()> sigReadyRead()
SignalProxy< void(const SocketNotifier &sock, int evTypes) sigActivated)()
static Ptr create(int domain, int type, int protocol)
SignalProxy< void()> sigDisconnected()
SignalProxy< void()> sigIncomingConnection()
std::shared_ptr< Socket > Ptr
std::shared_ptr< SocketNotifier > makeNotifier(const bool enabled=true) const
String related utilities and Regular expression matching.
int & logControlValidFlag()
void putStream(const std::string &group_r, LogLevel level_r, const char *file_r, const char *func_r, int line_r, const std::string &buffer_r)
That's what Loglinebuf calls.
LogLevel
Definition of log levels.
@ E_XXX
Excessive logging.
std::ostream & getStream(const char *group_r, LogLevel level_r, const char *file_r, const char *func_r, const int line_r)
Return a log stream to write on.
static constexpr std::string_view WH
static constexpr std::string_view OO
static constexpr std::string_view YE
static constexpr std::string_view CY
static constexpr std::string_view GR
std::string tracestr(char tag_r, unsigned depth_r, const std::string &msg_r, const char *file_r, const char *fnc_r, int line_r)
static constexpr std::string_view MA
static constexpr std::string_view RE
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Easy-to use interface to the ZYPP dependency resolver.
constexpr bool always_false_v
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
constexpr std::string_view ZYPP_MAIN_THREAD_NAME("Zypp-main")
bool blockAllSignalsForCurrentThread()
bool trySocketConnection(int &sockFD, const SockAddr &addr, uint64_t timeout)
auto eintrSafeCall(Fun &&function, Args &&... args)
LogControl implementation (thread_local Singleton).
void putRawLine(std::string &&line)
void setLineWriter(const shared_ptr< LogControl::LineWriter > &writer_r)
NULL _lineWriter indicates no loggin.
static LogControlImpl * instance()
The LogControlImpl singleton.
static bool instanceHideThreadName()
LogControlImpl(LogControlImpl &&)=delete
LogControlImpl & operator=(const LogControlImpl &)=delete
std::ostream & operator<<(std::ostream &str, const LogControlImpl &)
Stream output.
LogControlImpl()
Singleton ctor.
static void instanceHideThreadName(bool onOff_r)
static void instanceSetLogToPPID(bool onOff_r)
StreamTable _streamtable
one streambuffer per group and level
static bool instanceLogToPPID()
Hint for formatter wether we forward all logs to a parents log.
LogControlImpl(const LogControlImpl &)=delete
void excessive(bool onOff_r)
std::map< std::string, StreamSet > StreamTable
bool _logToPPIDMode
Hint for formatter to use the PPID and always show the thread name.
void setLineFormater(const shared_ptr< LogControl::LineFormater > &format_r)
Assert _lineFormater is not NULL.
std::ostream & getStream(const std::string &group_r, LogLevel level_r, const char *file_r, const char *func_r, const int line_r)
Provide the log stream to write (logger interface)
void logfile(const Pathname &logfile_r, mode_t mode_r=0640)
shared_ptr< LogControl::LineWriter > getLineWriter() const
std::map< LogLevel, StreamPtr > StreamSet
shared_ptr< LogControl::LineFormater > _lineFormater
LogControlImpl & operator=(LogControlImpl &&)=delete
bool hideThreadName() const
Hint for Formater whether to hide the thread name.
void putStream(const std::string &group_r, LogLevel level_r, const char *file_r, const char *func_r, int line_r, const std::string &message_r)
Format and write out a logline from Loglinebuf.
void hideThreadName(bool onOff_r)
zyppng::Socket::Ptr _sock
TriBool _hideThreadName
Hint for Formater whether to hide the thread name.
Osd(std::ostream &, int=0)
Osd & operator<<(Tp &&val)
FileLineWriter(const Pathname &file_r, mode_t mode_r=0)
Base class for ostream based LineWriter.
static ZYPP_API ThreadData & current()