41 static constexpr std::string_view
OO {
"\033[0m" };
42 static constexpr std::string_view
WH {
"\033[37;40m" };
43 static constexpr std::string_view
CY {
"\033[36;40m" };
44 static constexpr std::string_view
YE {
"\033[33;1;40m" };
45 static constexpr std::string_view
GR {
"\033[32;40m" };
46 static constexpr std::string_view
RE {
"\033[31;1;40m" };
47 static constexpr std::string_view
MA {
"\033[35;40m" };
51 std::string
tracestr(
char tag_r,
unsigned depth_r,
const char * file_r,
const char * fnc_r,
int line_r )
54 fmt % std::string(depth_r,tag_r) % file_r % fnc_r % line_r;
60 , _fnc(
std::move(fnc_r) )
76 : _strout { std::cerr }
78 { _strout << (i?
WH:
YE); }
116 int fd = ::open( file_r.
c_str(), O_CREAT|O_EXCL, mode_r );
121 std::ofstream * fstr = 0;
122 _outs.reset( (fstr =
new std::ofstream( file_r.
asString().c_str(), std::ios_base::app )) );
123 fstr->rdbuf()->pubsetbuf(0,0);
144 const std::string & message_r )
146 static char hostname[1024];
147 static char nohostname[] =
"unknown";
149 return str::form(
"%s <%d> %s(%d) [%s] %s(%s):%d %s",
150 now.c_str(), level_r,
151 ( gethostname( hostname, 1024 ) ? nohostname : hostname ),
154 file_r, func_r, line_r,
163 const char * file_r,
const char * func_r,
int line_r,
164 const std::string & buffer_r );
189 void tagSet(
const char * fil_r,
const char * fnc_r,
int lne_r )
198 virtual std::streamsize
xsputn(
const char * s, std::streamsize n )
199 {
return writeout( s, n ); }
211 virtual int writeout(
const char* s, std::streamsize n )
218 for (
int i = 0; i < n; ++i, ++c )
221 _buffer += std::string( s, c-s );
229 _buffer += std::string( s, c-s );
255 : _mybuf( group_r, level_r )
256 , _mystream( &_mybuf )
260 { _mystream.flush(); }
264 std::ostream &
getStream(
const char * fil_r,
const char * fnc_r,
int lne_r )
266 _mybuf.tagSet( fil_r, fnc_r, lne_r );
293 {
return _excessive; }
296 { _excessive = onOff_r; }
300 { _lineWriter = writer_r; }
303 {
return _lineWriter; }
309 _lineFormater = format_r;
316 if ( logfile_r.
empty() )
318 else if ( logfile_r ==
Pathname(
"-" ) )
341 if ( level_r ==
E_XXX && !_excessive )
344 if ( !_streamtable[group_r][level_r] )
346 _streamtable[group_r][level_r].reset(
new Loglinestream( group_r, level_r ) );
348 std::ostream & ret( _streamtable[group_r][level_r]->
getStream( file_r, func_r, line_r ) );
352 ret <<
"---<RESET LOGSTREAM FROM FAILED STATE]" << endl;
363 const std::string & message_r )
366 _lineWriter->writeOut( _lineFormater->format( group_r, level_r,
367 file_r, func_r, line_r,
384 , _excessive( getenv(
"ZYPP_FULLLOG") )
385 , _lineFormater( new
LogControl::LineFormater )
387 if ( getenv(
"ZYPP_LOGFILE") )
388 logfile( getenv(
"ZYPP_LOGFILE") );
390 if ( getenv(
"ZYPP_PROFILING") )
425 return str <<
"LogControlImpl";
449 const char * file_r,
const char * func_r,
int line_r,
450 const std::string & buffer_r )
453 file_r, func_r, line_r,
471 using logger::LogControlImpl;
std::map< LogLevel, StreamPtr > StreamSet
Osd & operator<<(Tp &&val)
LogLevel
Definition of log levels.
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)
static constexpr std::string_view MA
Base class for ostream based LineWriter.
void tagSet(const char *fil_r, const char *fnc_r, int lne_r)
Loglinestream(const std::string &group_r, LogLevel level_r)
static constexpr std::string_view WH
const char * c_str() const
String representation.
String related utilities and Regular expression matching.
void excessive(bool onOff_r)
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
LogControlImpl()
Singleton ctor.
Osd(std::ostream &, int=0)
void setLineWriter(const shared_ptr< LogControl::LineWriter > &writer_r)
NULL _lineWriter indicates no loggin.
void logfile(const Pathname &logfile_r, mode_t mode_r=0640)
void logfile(const Pathname &logfile_r)
Set path for the logfile.
static LogControl instance()
Singleton access.
std::ostream & operator<<(std::ostream &str, const LogControlImpl &obj)
void setLineWriter(const shared_ptr< LineWriter > &writer_r)
Assign a LineWriter.
void logToStdErr()
Log to std::err.
bool empty() const
Test for an empty path.
TraceLeave(const TraceLeave &)=delete
const std::string & _buffer
shared_ptr< LogControl::LineWriter > getLineWriter() const
const std::string & asString() const
String representation.
static constexpr std::string_view GR
friend std::ostream & operator<<(std::ostream &str, const LogControl &obj)
static constexpr std::string_view YE
virtual int overflow(int ch=EOF)
void setLineFormater(const shared_ptr< LogControl::LineFormater > &format_r)
Assert _lineFormater is not NULL.
shared_ptr< LogControl::LineFormater > _lineFormater
std::ostream & getStream(const char *fil_r, const char *fnc_r, int lne_r)
std::map< std::string, StreamSet > StreamTable
static constexpr std::string_view RE
void logNothing()
Turn off logging.
Maintain logfile related options.
virtual int writeout(const char *s, std::streamsize n)
static constexpr std::string_view OO
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.
shared_ptr< LogControl::LineWriter > _lineWriter
static Date now()
Return the current time.
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.
virtual std::streamsize xsputn(const char *s, std::streamsize n)
shared_ptr< LineWriter > getLineWriter() const
Get the current LineWriter.
static LogControlImpl & instance()
The LogControlImpl singleton.
Loglinebuf(const std::string &group_r, LogLevel level_r)
void setLineFormater(const shared_ptr< LineFormater > &formater_r)
Assign a LineFormater.
shared_ptr< Loglinestream > StreamPtr
Easy-to use interface to the ZYPP dependency resolver.
std::string tracestr(char tag_r, unsigned depth_r, const char *file_r, const char *fnc_r, int line_r)
static constexpr std::string_view CY
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.
LogControl implementation (Singleton).
FileLineWriter(const Pathname &file_r, mode_t mode_r=0)
StreamTable _streamtable
one streambuffer per group and level