fix name program in Windows

This commit is contained in:
Alexander Zhirov 2023-06-07 10:02:47 +03:00
parent b20b8fb55b
commit f9b4718549
4 changed files with 14 additions and 12 deletions

View File

@ -2,6 +2,8 @@
## [v0.4.0](https://git.zhirov.kz/dlang/singlog/compare/v0.3.2...v0.4.0) (2023.06.07) ## [v0.4.0](https://git.zhirov.kz/dlang/singlog/compare/v0.3.2...v0.4.0) (2023.06.07)
- Part of the code has been changed/rewritten
### New ### New
- Color output of messages to the terminal and console - Color output of messages to the terminal and console

View File

@ -43,7 +43,7 @@ Setting the name of the logged program (it matters for Windows OS):
log.program("My program"); log.program("My program");
``` ```
Color output setting (`false` by default): Setting the status of color text output (`false` by default):
```d ```d
log.color(true); log.color(true);

View File

@ -18,7 +18,7 @@
"name": "test", "name": "test",
"targetType": "executable", "targetType": "executable",
"targetPath": "bin", "targetPath": "bin",
"targetName": "app", "targetName": "test",
"importPaths": ["source","tests"], "importPaths": ["source","tests"],
"sourcePaths": ["tests"] "sourcePaths": ["tests"]
} }

View File

@ -50,7 +50,7 @@ class Log {
private: private:
static Log _log; static Log _log;
string _path; string _path;
string _name = "singlog"; wstring _name = "singlog";
bool _writeToFile = true; bool _writeToFile = true;
bool _ccolor = false; bool _ccolor = false;
@ -69,7 +69,7 @@ version(Windows) {
void writesyslog(string message, WORD priority) { void writesyslog(string message, WORD priority) {
import std.utf: toUTF16z; import std.utf: toUTF16z;
auto wMessage = message.toUTF16z(); auto wMessage = message.toUTF16z();
HANDLE handleEventLog = RegisterEventSourceA(NULL, this._name.toStringz()); HANDLE handleEventLog = RegisterEventSourceW(NULL, this._name.ptr);
if (handleEventLog == NULL) if (handleEventLog == NULL)
return; return;
@ -79,13 +79,13 @@ version(Windows) {
} }
WORD[] _color = [ WORD[] _color = [
FOREGROUND_GREEN, FOREGROUND_GREEN, // green
FOREGROUND_BLUE, FOREGROUND_BLUE, // blue
FOREGROUND_RED | FOREGROUND_BLUE, FOREGROUND_RED | FOREGROUND_BLUE, // magenta
FOREGROUND_RED, FOREGROUND_RED, // red
FOREGROUND_RED | FOREGROUND_GREEN, FOREGROUND_RED | FOREGROUND_GREEN, // yellow
FOREGROUND_BLUE | FOREGROUND_GREEN, FOREGROUND_BLUE | FOREGROUND_GREEN, // cyan
FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN // white
]; ];
void colorTextOutput(string time, wstring message, int priority) { void colorTextOutput(string time, wstring message, int priority) {
@ -241,7 +241,7 @@ public:
} }
Log output(int outs) { this._output = outs; return this._log; } Log output(int outs) { this._output = outs; return this._log; }
Log program(string name) { this._name = name; return this._log; } Log program(string name) { this._name = name.to!wstring; return this._log; }
Log file(string path) { this._path = path; return this._log; } Log file(string path) { this._path = path; return this._log; }
Log level(int priority) { this._priority = priority; return this._log; } Log level(int priority) { this._priority = priority; return this._log; }
Log color(bool condition) { this._ccolor = condition; return this._log; } Log color(bool condition) { this._ccolor = condition; return this._log; }