diff --git a/uppsrc/Core/Diag.h b/uppsrc/Core/Diag.h index 1b5a62b15..a933f635b 100644 --- a/uppsrc/Core/Diag.h +++ b/uppsrc/Core/Diag.h @@ -8,7 +8,7 @@ const char LOG_BEGIN = '\x1e'; const char LOG_END = '\x1f'; enum LogOptions { - LOG_FILE = 1, LOG_COUT = 2, LOG_CERR = 4, LOG_DBG = 8, LOG_SYS = 16, + LOG_FILE = 1, LOG_COUT = 2, LOG_CERR = 4, LOG_DBG = 8, LOG_SYS = 16, LOG_ELAPSED = 128, LOG_TIMESTAMP = 256, LOG_TIMESTAMP_UTC = 512, LOG_APPEND = 1024, LOG_ROTATE_GZIP = 2048, }; diff --git a/uppsrc/Core/Log.cpp b/uppsrc/Core/Log.cpp index ac15e669e..b0d070331 100644 --- a/uppsrc/Core/Log.cpp +++ b/uppsrc/Core/Log.cpp @@ -39,6 +39,8 @@ struct LogOut { bool line_begin; + int prev_msecs; + void Create(bool append); void Create() { Create(options & LOG_APPEND); } void Close(); @@ -180,9 +182,18 @@ void LogOut::Line(const char *s, int len, int depth) char h[600]; char *p = h; int ll = 0; + if(options & LOG_ELAPSED) { + int t = msecs(); + int e = prev_msecs ? t - prev_msecs : 0; + ll = sprintf(p, "[+%6d ms] ", e); + if(ll < 0) + return; + p += ll; + prev_msecs = t; + } if((options & (LOG_TIMESTAMP|LOG_TIMESTAMP_UTC)) && line_begin) { Time t = (options & LOG_TIMESTAMP_UTC) ? GetUtcTime() : GetSysTime(); - ll = sprintf(h, "%02d.%02d.%04d %02d:%02d:%02d ", + ll = sprintf(p, "%02d.%02d.%04d %02d:%02d:%02d ", t.day, t.month, t.year, t.hour, t.minute, t.second); if(ll < 0) return; diff --git a/uppsrc/Core/src.tpp/Logging_en-us.tpp b/uppsrc/Core/src.tpp/Logging_en-us.tpp index 69b719471..4f564a621 100644 --- a/uppsrc/Core/src.tpp/Logging_en-us.tpp +++ b/uppsrc/Core/src.tpp/Logging_en-us.tpp @@ -1,5 +1,4 @@ topic "U++ Logging"; -[2 $$0,0#00000000000000000000000000000000:Default] [i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] [l288;2 $$2,2#27521748481378242620020725143825:desc] [0 $$3,0#96390100711032703541132217272105:end] @@ -9,6 +8,7 @@ topic "U++ Logging"; [l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] [i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] [b42;2 $$9,9#13035079074754324216151401829390:normal] +[2 $$0,0#00000000000000000000000000000000:Default] [{_}%EN-US [ {{10000@(113.42.0) [s0; [*@7;4 U`+`+ Logging]]}}&] [s0;i448;a25;kKO9;@(0.0.255)%- &] @@ -51,6 +51,9 @@ is ConfigFile(`"[/ program`_name].log`").] :: [s0; Output log to debugger (Win32 specific).] :: [s0; LOG`_SYS ] :: [s0; Output log to syslog (POSIX specific).] +:: [s0; LOG`_ELAPSED] +:: [s0; Prepend a number of miliseconds to each log line since the previous +log line.] :: [s0; LOG`_TIMESTAMP ] :: [s0; Prepend local time timestamp to each log line (not with LOG`_SYS, as syslog already does this).]