- 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
This commit is contained in:
Alexander Zhirov 2023-06-01 18:23:07 +03:00
parent 06784491cd
commit e5f6ab5c4d
4 changed files with 19 additions and 10 deletions

View File

@ -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

View File

@ -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"`.

View File

@ -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;

BIN
tests/output.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB