106 long flags = fcntl(
fgStdPipe[0], F_GETFL);
130 memset(buffer, 0,
sizeof(buffer));
131 int len = read(
fgStdPipe[0], buffer,
sizeof(buffer)-1);
134 if (len == 0)
return;
138 printf(
"%s", buffer);
159 const char *go4sys = gSystem->Getenv(
"GO4SYS");
161 if (!go4sys || (strlen(go4sys) == 0)) go4sys = COMP_GO4SYS;
163 if (!go4sys || (strlen(go4sys) == 0))
return "";
168 char lastsymbol =
'\\';
171 char lastsymbol =
'/';
191 const char *go4sys =
GO4SYS();
193 if (!subdir || (strlen(subdir) == 0))
return TString(go4sys);
195 TString res = go4sys;
198 res += TString(subdir).ReplaceAll(
"/",
"\\");
213 va_start(args, text);
214 vsnprintf(txtbuf,
fguMESLEN-20, text, args);
219 case -1: prefix =
fgcINFO;
break;
221 case 1: prefix =
fgcINFO;
break;
222 case 2: prefix =
fgcWARN;
break;
223 case 3: prefix =
fgcERR;
break;
259 fprintf(stdout,
"%s", text);
262 fprintf(stderr,
"%s", text);
274 int width = (rate > 1e4) ? 0 : (rate < 1. ? 3 : 1);
275 fprintf(stdout,
"\rCnt = %llu Rate = %5.*f Ev/s", cnt, width, rate);
288 va_start(args, text);
289 vsnprintf(txtbuf,
fguMESLEN, text, args);
301 va_start(args, text);
302 vsnprintf(txtbuf,
fguMESLEN, text, args);
314 va_start(args, text);
315 vsnprintf(txtbuf,
fguMESLEN, text, args);
326 va_start(args, text);
327 vsnprintf(txtbuf,
fguMESLEN, text, args);
392 snprintf(txtbuf,
fguMESLEN,
"go4log-%d.txt", gSystem->GetPid());
396 std::ofstream* lf =
new std::ofstream(txtbuf, appendmode ? std::ios::app : std::ios::out);
401 std::cerr <<
"TGo4Log::OpenLogfile() - Error opening logfile "<< name << std::endl;
410 catch(std::exception& ex)
412 std::cerr <<
"standard exception "<<ex.what()<<
"in TGo4Log::OpenLogfile" << std::endl;
416 std::cerr <<
"!!! Unexpected exception in TGo4Log::OpenLogfile !!!" << std::endl;
425 std::ofstream *lf =
static_cast<std::ofstream*
>(
fgxLogfile);
429 *lf << now.AsSQLString() <<
": ";
431 *lf << text << std::endl;
434 catch(std::exception& ex)
436 std::cerr <<
"standard exception "<<ex.what()<<
"in TGo4Log::WriteLogfile" << std::endl;
440 std::cerr <<
"!!! Unexpected exception in TGo4Log::WriteLogfile !!!" << std::endl;
454 catch(std::exception& ex)
456 std::cerr <<
"standard exception "<<ex.what()<<
"in TGo4Log::CloseLogfile" << std::endl;
460 std::cerr <<
"!!! Unexpected exception in TGo4Log::CloseLogfile !!!" << std::endl;
#define __MESSAGETEXTLENGTH__
This class handles all logging messages inside Go4.
static const char * fgcDEFAULTLOG
Name of default logfile.
static TGo4Log * Instance()
static TString subGO4SYS(const char *subdir)
Return subdirectory in the GO4SYS.
static void Warn(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 2.
static Bool_t IsAutoEnabled()
get current user boolean
static void ProcessRedirection(int kind=0)
static void Info(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 1.
static void PrintRate(ULong64_t cnt, double rate)
Printout rate and events count, handle redirection.
static Bool_t fgbOutputEnabled
General switch on/off log output.
static const char * GetLogname()
get name of last opened logfile
static void WriteLogfile(const char *text, Bool_t withtime=kTRUE)
Write text to current logfile if this is open.
static const char * Message(Int_t prio, const char *text,...) GO4_PRINTF2_ARGS
Display a message.
static const char * GO4SYS()
Return GO4SYS environment variable or Go4 top directory during compile (if GO4SYS) not set.
static const char * fgcINFO
Info message indicator.
static char fgcMessagetext[__MESSAGETEXTLENGTH__]
Keeps latest message with all format indicators.
static Bool_t IsLogfileEnabled()
get current logfile state
static void Printf(Bool_t _stdout, const char *text)
Make direct printf without log file or logger.
static const char * fgcRIGHT
Prompt character right side.
static const char * fgcERR
Error message indicator.
static void SetIgnoreLevel(Int_t level)
Define threshold for output.
static const char * fgcWARN
Warning message indicator.
static void LogfileEnable(Bool_t on=kTRUE)
switch writing to logfile on or off
static void SetSniffer(TNamed *sniff)
static int fgStdPipe[2]
optional object to get all output via SetTitle method
static Int_t fgiIgnoreLevel
all Messages with lower level are suppressed
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
static const char * fgcDEBUG
System debug message indicator.
static TString fgxLogName
Name of last logfile set.
static const char * GO4INCPATH()
Return include path for this Go4 installation.
static void AutoEnable(Bool_t on=kTRUE)
set boolean for user action
static TMutex * fgxMutex
we use own mutex to protect the logging instance
static void EnableRedirection()
static void OutputEnable(Bool_t on=kTRUE)
switch output on or off
static void Error(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 3.
static int fgStdSave
redirected pipe for stdout
static Bool_t fgbAutoMode
User boolean to write log on demand or not.
static Bool_t IsOutputEnabled()
get current output state
static TNamed * fgSniffer
value of GO4SYS during run
static Int_t GetIgnoreLevel()
Get threshold for output.
static void OpenLogfile(const char *name=nullptr, const char *headercomment=nullptr, Bool_t appendmode=kFALSE)
Open file of name for logmessage output.
static void * fgxLogfile
optional logfile to store messages with time
static void CloseLogfile()
Close logfile if existing.
static const char * fgcLEFT
Prompt character left side.
static const char * GetDefaultLogname()
Return default name of log file.
static Bool_t fgbLogfileEnabled
General switch on/off log file output.
static TGo4Log * fgxInstance
static TLogTimer * fgTimer
saved file for stdout
TLogTimer(Int_t millisec)