1
0
Fork 0

Merge pull request 'v0.3.2' (#3) from dev into master

Reviewed-on: dlang/singlog#3
This commit is contained in:
Alexander Zhirov 2023-06-01 15:25:26 +00:00
commit 5dd910b683
4 changed files with 19 additions and 10 deletions

View File

@ -1,5 +1,10 @@
# Changelog # 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) ## [v0.3.1](https://git.zhirov.kz/dlang/singlog/compare/v0.3.0...v0.3.1) (2023.05.30)
### Bug fixes ### Bug fixes

View File

@ -27,6 +27,8 @@ void main(string[] argv) {
} }
``` ```
![output](tests/output.png)
## Examples ## Examples
Setting the name of the logged program (it matters for Windows OS): 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 ## 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 msgOutput = STDOUT;
int msgLevel = INFORMATION; int msgLevel = INFORMATION;
void writeLog(string message, int msgLevel) { void writeLog(string message, string type, int msgLevel) {
if (this.msgLevel > msgLevel) if (this.msgLevel > msgLevel)
return; return;
if (this.msgOutput & 1) if (this.msgOutput & 1)
syslog(sysLevel[msgLevel], message.toStringz()); 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) if (this.msgOutput & 2)
writeln(message); writeln(message);
if (this.msgOutput & 4) if (this.msgOutput & 4)
@ -142,7 +144,7 @@ version(Windows) {
} }
try { try {
file.writeln(Clock.currTime().format("%Y.%m.%d %H:%M:%S: ") ~ message); file.writeln(message);
} catch (Exception e) { } catch (Exception e) {
this.writeToFile = false; this.writeToFile = false;
this.error("Unable to write to the log file " ~ this.path); 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 file(string path) { this.path = path; return this.log; }
Log level(int msgLevel) { this.msgLevel = msgLevel; return this.log; } Log level(int msgLevel) { this.msgLevel = msgLevel; return this.log; }
void alert(T)(T message) { writeLog(message.to!string, ALERT); } void alert(T)(T message) { writeLog(message.to!string, "ALERT", ALERT); }
void critical(T)(T message) { writeLog(message.to!string, CRITICAL); } void critical(T)(T message) { writeLog(message.to!string, "CRITICAL", CRITICAL); }
void error(T)(T message) { writeLog(message.to!string, ERROR); } void error(T)(T message) { writeLog(message.to!string, "ERROR", ERROR); }
void warning(T)(T message) { writeLog(message.to!string, WARNING); } void warning(T)(T message) { writeLog(message.to!string, "WARNING", WARNING); }
void notice(T)(T message) { writeLog(message.to!string, NOTICE); } void notice(T)(T message) { writeLog(message.to!string, "NOTICE", NOTICE); }
void information(T)(T message) { writeLog(message.to!string, INFORMATION); } void information(T)(T message) { writeLog(message.to!string, "INFORMATION", INFORMATION); }
void debugging(T)(T message) { writeLog(message.to!string, DEBUGGING); } void debugging(T)(T message) { writeLog(message.to!string, "DEBUGGING", DEBUGGING); }
alias a = alert; alias a = alert;
alias c = critical; alias c = critical;

BIN
tests/output.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB