diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ba884f..90e1f38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [v0.3.2](https://git.zhirov.kz/dlang/singlog/compare/v0.3.1...v0.3.2) (2023.06.01) + +- Printing information about the type of the logged message to the standard output stream and file +- Printing the date and time to the standard output stream + ## [v0.3.1](https://git.zhirov.kz/dlang/singlog/compare/v0.3.0...v0.3.1) (2023.05.30) ### Bug fixes diff --git a/README.md b/README.md index 8d57452..039b392 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ void main(string[] argv) { } ``` +![output](tests/output.png) + ## Examples Setting the name of the logged program (it matters for Windows OS): @@ -75,4 +77,4 @@ log.d("Debugging message") => log.debugging("Debugging message"); ## DUB -Add a dependency on `"singlog": "~>0.3.1"`. +Add a dependency on `"singlog": "~>0.3.2"`. diff --git a/source/singlog.d b/source/singlog.d index 30976db..0202885 100644 --- a/source/singlog.d +++ b/source/singlog.d @@ -109,11 +109,13 @@ version(Windows) { int msgOutput = STDOUT; int msgLevel = INFORMATION; - void writeLog(string message, int msgLevel) { + void writeLog(string message, string type, int msgLevel) { if (this.msgLevel > msgLevel) return; if (this.msgOutput & 1) syslog(sysLevel[msgLevel], message.toStringz()); + if (this.msgOutput & 6) + message = format("%s [%s]: %s", Clock.currTime().format("%Y.%m.%d %H:%M:%S"), type, message); if (this.msgOutput & 2) writeln(message); if (this.msgOutput & 4) @@ -142,7 +144,7 @@ version(Windows) { } try { - file.writeln(Clock.currTime().format("%Y.%m.%d %H:%M:%S: ") ~ message); + file.writeln(message); } catch (Exception e) { this.writeToFile = false; this.error("Unable to write to the log file " ~ this.path); @@ -173,13 +175,13 @@ public: Log file(string path) { this.path = path; return this.log; } Log level(int msgLevel) { this.msgLevel = msgLevel; return this.log; } - void alert(T)(T message) { writeLog(message.to!string, ALERT); } - void critical(T)(T message) { writeLog(message.to!string, CRITICAL); } - void error(T)(T message) { writeLog(message.to!string, ERROR); } - void warning(T)(T message) { writeLog(message.to!string, WARNING); } - void notice(T)(T message) { writeLog(message.to!string, NOTICE); } - void information(T)(T message) { writeLog(message.to!string, INFORMATION); } - void debugging(T)(T message) { writeLog(message.to!string, DEBUGGING); } + void alert(T)(T message) { writeLog(message.to!string, "ALERT", ALERT); } + void critical(T)(T message) { writeLog(message.to!string, "CRITICAL", CRITICAL); } + void error(T)(T message) { writeLog(message.to!string, "ERROR", ERROR); } + void warning(T)(T message) { writeLog(message.to!string, "WARNING", WARNING); } + void notice(T)(T message) { writeLog(message.to!string, "NOTICE", NOTICE); } + void information(T)(T message) { writeLog(message.to!string, "INFORMATION", INFORMATION); } + void debugging(T)(T message) { writeLog(message.to!string, "DEBUGGING", DEBUGGING); } alias a = alert; alias c = critical; diff --git a/tests/output.png b/tests/output.png new file mode 100644 index 0000000..7d024e3 Binary files /dev/null and b/tests/output.png differ