mirror of https://github.com/buggins/dlangui.git
fix #213 - logging broken by commit e89b684274 Solution: added methods Log.fv, fd, fi, fw, fe, ff which are format line versions of Log.v,d,i,w,e,f
This commit is contained in:
parent
3f6662d85a
commit
cb51dc04b1
|
|
@ -21,6 +21,8 @@ setLogLevel(LogLeve.Debug);
|
|||
|
||||
// log debug message
|
||||
Log.d("mouse clicked at ", x, ",", y);
|
||||
// or with format string:
|
||||
Log.fd("mouse clicked at %d,%d", x, y);
|
||||
// log error message
|
||||
Log.e("exception while reading file", e);
|
||||
----
|
||||
|
|
@ -33,6 +35,7 @@ module dlangui.core.logger;
|
|||
|
||||
import std.stdio;
|
||||
import std.datetime : SysTime, Clock;
|
||||
import core.sync.mutex;
|
||||
|
||||
/// Log levels
|
||||
enum LogLevel : int {
|
||||
|
|
@ -77,8 +80,6 @@ Log.e("exception while reading file", e);
|
|||
|
||||
*/
|
||||
|
||||
import core.sync.mutex;
|
||||
|
||||
class Log {
|
||||
static __gshared private LogLevel logLevel = LogLevel.Info;
|
||||
static __gshared private std.stdio.File * logFile = null;
|
||||
|
|
@ -141,6 +142,15 @@ class Log {
|
|||
}
|
||||
/// Log message with arbitrary log level
|
||||
static public void log(S...)(LogLevel level, S args) {
|
||||
if (logLevel >= level && logFile !is null && logFile.isOpen) {
|
||||
SysTime ts = Clock.currTime();
|
||||
logFile.writef("%04d-%02d-%02d %02d:%02d:%02d.%03d %s ", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fracSecs.split!("msecs").msecs, logLevelName(level));
|
||||
logFile.writeln(args);
|
||||
logFile.flush();
|
||||
}
|
||||
}
|
||||
/// Log message with arbitrary log level with format string
|
||||
static public void logf(S...)(LogLevel level, S args) {
|
||||
if (logLevel >= level && logFile !is null && logFile.isOpen) {
|
||||
SysTime ts = Clock.currTime();
|
||||
logFile.writef("%04d-%02d-%02d %02d:%02d:%02d.%03d %s ", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fracSecs.split!("msecs").msecs, logLevelName(level));
|
||||
|
|
@ -155,6 +165,13 @@ class Log {
|
|||
log(LogLevel.Trace, args);
|
||||
}
|
||||
}
|
||||
/// Log verbose / trace message with format string
|
||||
static public void fv(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
if (logLevel >= LogLevel.Trace && logFile !is null && logFile.isOpen)
|
||||
logf(LogLevel.Trace, args);
|
||||
}
|
||||
}
|
||||
/// Log debug message
|
||||
static public void d(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
|
|
@ -162,6 +179,13 @@ class Log {
|
|||
log(LogLevel.Debug, args);
|
||||
}
|
||||
}
|
||||
/// Log debug message with format string
|
||||
static public void fd(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
if (logLevel >= LogLevel.Debug && logFile !is null && logFile.isOpen)
|
||||
logf(LogLevel.Debug, args);
|
||||
}
|
||||
}
|
||||
/// Log info message
|
||||
static public void i(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
|
|
@ -169,6 +193,13 @@ class Log {
|
|||
log(LogLevel.Info, args);
|
||||
}
|
||||
}
|
||||
/// Log info message
|
||||
static public void fi(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
if (logLevel >= LogLevel.Info && logFile !is null && logFile.isOpen)
|
||||
logf(LogLevel.Info, args);
|
||||
}
|
||||
}
|
||||
/// Log warn message
|
||||
static public void w(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
|
|
@ -176,6 +207,13 @@ class Log {
|
|||
log(LogLevel.Warn, args);
|
||||
}
|
||||
}
|
||||
/// Log warn message
|
||||
static public void fw(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
if (logLevel >= LogLevel.Warn && logFile !is null && logFile.isOpen)
|
||||
logf(LogLevel.Warn, args);
|
||||
}
|
||||
}
|
||||
/// Log error message
|
||||
static public void e(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
|
|
@ -183,6 +221,13 @@ class Log {
|
|||
log(LogLevel.Error, args);
|
||||
}
|
||||
}
|
||||
/// Log error message
|
||||
static public void fe(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
if (logLevel >= LogLevel.Error && logFile !is null && logFile.isOpen)
|
||||
logf(LogLevel.Error, args);
|
||||
}
|
||||
}
|
||||
/// Log fatal error message
|
||||
static public void f(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
|
|
@ -190,6 +235,13 @@ class Log {
|
|||
log(LogLevel.Fatal, args);
|
||||
}
|
||||
}
|
||||
/// Log fatal error message
|
||||
static public void ff(S...)(S args) {
|
||||
synchronized(mutex) {
|
||||
if (logLevel >= LogLevel.Fatal && logFile !is null && logFile.isOpen)
|
||||
logf(LogLevel.Fatal, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug {
|
||||
|
|
|
|||
Loading…
Reference in New Issue