Skip to content

Commit 74335fb

Browse files
authored
fix: Remove Moment.js dependency (#28797)
1 parent 8b4a4be commit 74335fb

File tree

4 files changed

+6
-16
lines changed

4 files changed

+6
-16
lines changed

lib/util/logger.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import assert from "node:assert";
22
import fs from "node:fs";
33
import path from "node:path";
44

5-
import moment from "moment";
65
import {rimrafSync} from "rimraf";
76
import winston from "winston";
8-
97
import * as settings from "./settings";
108

119
const NAMESPACE_SEPARATOR = ":";
@@ -31,7 +29,7 @@ class Logger {
3129
// What transports to enable
3230
this.output = settings.get().advanced.log_output;
3331
// Directory to log to
34-
const timestamp = moment(Date.now()).format("YYYY-MM-DD.HH-mm-ss");
32+
const timestamp = new Date().toISOString().slice(0, 19).replace("T", ".").replace(/:/g, "-");
3533
this.directory = settings.get().advanced.log_directory.replace("%TIMESTAMP%", timestamp);
3634
const logFilename = settings.get().advanced.log_file.replace("%TIMESTAMP%", timestamp);
3735
this.level = settings.get().advanced.log_level;
@@ -40,11 +38,12 @@ class Logger {
4038

4139
assert(settings.LOG_LEVELS.includes(this.level), `'${this.level}' is not valid log_level, use one of '${settings.LOG_LEVELS.join(", ")}'`);
4240

43-
const timestampFormat = (): string => moment().format(settings.get().advanced.timestamp_format);
44-
4541
this.logger = winston.createLogger({
4642
level: "debug",
47-
format: winston.format.combine(winston.format.errors({stack: true}), winston.format.timestamp({format: timestampFormat})),
43+
format: winston.format.combine(
44+
winston.format.errors({stack: true}),
45+
winston.format.timestamp({format: settings.get().advanced.timestamp_format}),
46+
),
4847
levels: winston.config.syslog.levels,
4948
});
5049

lib/util/settings.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@
784784
"type": "string",
785785
"title": "Timestamp format",
786786
"requiresRestart": true,
787-
"description": "Log timestamp format",
787+
"description": "Log timestamp format (see https://github.com/taylorhakes/fecha?tab=readme-ov-file#formatting-tokens for all supported tokens)",
788788
"default": "YYYY-MM-DD HH:mm:ss",
789789
"examples": ["YYYY-MM-DD HH:mm:ss.SSS"]
790790
},

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"js-yaml": "^4.1.0",
5353
"json-stable-stringify-without-jsonify": "^1.0.1",
5454
"jszip": "^3.10.1",
55-
"moment": "^2.30.1",
5655
"mqtt": "^5.14.1",
5756
"object-assign-deep": "^0.4.0",
5857
"rimraf": "^6.0.1",

pnpm-lock.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)