Skip to content

Commit f981f9e

Browse files
committed
Implement splat serialization
1 parent eff9cfb commit f981f9e

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"ejs": "^3.1.5",
2929
"express": "^4.17.1",
3030
"multer": "^1.4.2",
31+
"safe-stable-stringify": "^1.1.1",
3132
"spotify-web-api-node": "^5.0.0",
3233
"superagent": "^6.1.0",
3334
"winston": "^3.3.3",

utils.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import fs, {promises, constants} from "fs";
22
import dayjs from 'dayjs';
33
import utc from 'dayjs/plugin/utc.js';
44
import winston from "winston";
5+
import jsonStringify from 'safe-stable-stringify';
56

67
const {format } = winston;
7-
const {combine, printf, timestamp, padLevels, label, splat } = format;
8+
const {combine, printf, timestamp, padLevels, label, splat, simple} = format;
89

910
dayjs.extend(utc);
1011

@@ -74,14 +75,16 @@ export const buildTrackString = (playObj) => {
7475
export const sortByPlayDate = (a, b) => a.data.playDate.isAfter(b.data.playDate) ? 1 : -1;
7576

7677
const s = splat();
77-
//const SPLAT = Symbol.for('splat')
78+
const SPLAT = Symbol.for('splat')
7879

7980
let longestLabel = 3;
80-
export const defaultFormat = printf(({level, message, label = 'App', timestamp, /*[SPLAT]: splatInfo = {}, ...rest*/}) => {
81+
export const defaultFormat = printf(({level, message, label = 'App', timestamp, [SPLAT] : splatObj}) => {
82+
let stringifyValue = splatObj !== undefined ? jsonStringify(splatObj) : '';
8183
if(label.length > longestLabel) {
8284
longestLabel = label.length;
8385
}
84-
return `${timestamp} ${level.padEnd(7)}: [${label.padEnd(longestLabel)}] ${message}`;
86+
87+
return `${timestamp} ${level.padEnd(7)}: [${label.padEnd(longestLabel)}] ${message}${stringifyValue !== '' ? ` ${stringifyValue}` : ''}`;
8588
});
8689

8790
export const labelledFormat = (labelName = 'App') => {

0 commit comments

Comments
 (0)