43 if ( file_r == Pathname(
"-") )
53 int fd = ::open( file_r.c_str(), O_CREAT|O_EXCL, mode_r );
58 std::ofstream * fstr = 0;
59 _outs.reset( (fstr =
new std::ofstream( file_r.asString().c_str(), std::ios_base::app )) );
60 fstr->rdbuf()->pubsetbuf(0,0);
81 const std::string & message_r )
83 static char hostname[1024];
84 static char nohostname[] =
"unknown";
86 return str::form(
"%s <%d> %s(%d) [%s] %s(%s):%d %s",
88 ( gethostname( hostname, 1024 ) ? nohostname : hostname ),
91 file_r, func_r, line_r,
100 const char * file_r,
const char * func_r,
int line_r,
101 const std::string & buffer_r );
126 void tagSet(
const char * fil_r,
const char * fnc_r,
int lne_r )
135 virtual std::streamsize xsputn(
const char * s, std::streamsize n )
136 {
return writeout( s, n ); }
138 virtual int overflow(
int ch = EOF )
148 virtual int writeout(
const char* s, std::streamsize n )
155 for (
int i = 0; i < n; ++i, ++c )
158 _buffer += std::string( s, c-s );
166 _buffer += std::string( s, c-s );
192 : _mybuf( group_r, level_r )
193 , _mystream( &_mybuf )
197 { _mystream.flush(); }
201 std::ostream &
getStream(
const char * fil_r,
const char * fnc_r,
int lne_r )
203 _mybuf.tagSet( fil_r, fnc_r, lne_r );
230 {
return _excessive; }
232 void excessive(
bool onOff_r )
233 { _excessive = onOff_r; }
237 { _lineWriter = writer_r; }
240 {
return _lineWriter; }
246 _lineFormater = format_r;
251 void logfile(
const Pathname & logfile_r, mode_t mode_r = 0640 )
253 if ( logfile_r.empty() )
255 else if ( logfile_r == Pathname(
"-" ) )
278 if ( level_r ==
E_XXX && !_excessive )
281 if ( !_streamtable[group_r][level_r] )
283 _streamtable[group_r][level_r].reset(
new Loglinestream( group_r, level_r ) );
285 return _streamtable[group_r][level_r]->getStream( file_r, func_r, line_r );
294 const std::string & message_r )
297 _lineWriter->writeOut( _lineFormater->format( group_r, level_r,
298 file_r, func_r, line_r,
315 , _excessive( getenv(
"ZYPP_FULLLOG") )
316 , _lineFormater( new
LogControl::LineFormater )
318 if ( getenv(
"ZYPP_LOGFILE") )
319 logfile( getenv(
"ZYPP_LOGFILE") );
321 if ( getenv(
"ZYPP_PROFILING") )
356 return str <<
"LogControlImpl";
371 return LogControlImpl::instance().getStream( group_r,
380 const char * file_r,
const char * func_r,
int line_r,
381 const std::string & buffer_r )
383 LogControlImpl::instance().putStream( group_r, level_r,
384 file_r, func_r, line_r,
389 {
return LogControlImpl::instance().isExcessive(); }
402 using logger::LogControlImpl;
405 { LogControlImpl::instance().logfile( logfile_r ); }
408 { LogControlImpl::instance().logfile( logfile_r, mode_r ); }
411 {
return LogControlImpl::instance().getLineWriter(); }
414 { LogControlImpl::instance().setLineWriter( writer_r ); }
417 { LogControlImpl::instance().setLineFormater( formater_r ); }
420 { LogControlImpl::instance().setLineWriter( shared_ptr<LineWriter>() ); }
431 { LogControlImpl::instance().excessive(
true ); }
433 { LogControlImpl::instance().excessive(
false ); }
442 return str << LogControlImpl::instance();