mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-07-04 11:01:40 +00:00
fix: log dir tz format not working on some systems (#30324)
This commit is contained in:
+7
-2
@@ -21,8 +21,13 @@ class Logger {
|
||||
public init(): void {
|
||||
// What transports to enable
|
||||
this.output = settings.get().advanced.log_output;
|
||||
// NOTE: Sweden uses ISO standard, hence, this works for our purpose (equiv of toISOString with proper tz)
|
||||
const timestamp = new Date().toLocaleString("sv-SE").slice(0, 19).replace(" ", ".").replaceAll(":", "-");
|
||||
const date = new Date();
|
||||
// offset UTC by current timezone, ISO keeps "Z" (UTC) which is then wrong but we strip it
|
||||
const timestamp = new Date(date.getTime() - date.getTimezoneOffset() * 60000)
|
||||
.toISOString()
|
||||
.slice(0, 19)
|
||||
.replace("T", ".")
|
||||
.replaceAll(":", "-");
|
||||
this.directory = settings.get().advanced.log_directory.replace("%TIMESTAMP%", timestamp);
|
||||
const logFilename = settings.get().advanced.log_file.replace("%TIMESTAMP%", timestamp);
|
||||
this.level = settings.get().advanced.log_level;
|
||||
|
||||
@@ -51,6 +51,7 @@ describe("Logger", () => {
|
||||
it("Create log directory", () => {
|
||||
const dirs = fs.readdirSync(dir.name);
|
||||
expect(dirs.length).toBe(1);
|
||||
expect(dirs[0]).toMatch(/^[0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]{2}-[0-9]{2}-[0-9]{2}$/);
|
||||
});
|
||||
|
||||
it("Should cleanup (default setting)", () => {
|
||||
|
||||
Reference in New Issue
Block a user