Skip to content

Commit

Permalink
Implement splat serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Nov 24, 2020
1 parent eff9cfb commit f981f9e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"ejs": "^3.1.5",
"express": "^4.17.1",
"multer": "^1.4.2",
"safe-stable-stringify": "^1.1.1",
"spotify-web-api-node": "^5.0.0",
"superagent": "^6.1.0",
"winston": "^3.3.3",
Expand Down
11 changes: 7 additions & 4 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import fs, {promises, constants} from "fs";
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js';
import winston from "winston";
import jsonStringify from 'safe-stable-stringify';

const {format } = winston;
const {combine, printf, timestamp, padLevels, label, splat } = format;
const {combine, printf, timestamp, padLevels, label, splat, simple} = format;

dayjs.extend(utc);

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

const s = splat();
//const SPLAT = Symbol.for('splat')
const SPLAT = Symbol.for('splat')

let longestLabel = 3;
export const defaultFormat = printf(({level, message, label = 'App', timestamp, /*[SPLAT]: splatInfo = {}, ...rest*/}) => {
export const defaultFormat = printf(({level, message, label = 'App', timestamp, [SPLAT] : splatObj}) => {
let stringifyValue = splatObj !== undefined ? jsonStringify(splatObj) : '';
if(label.length > longestLabel) {
longestLabel = label.length;
}
return `${timestamp} ${level.padEnd(7)}: [${label.padEnd(longestLabel)}] ${message}`;

return `${timestamp} ${level.padEnd(7)}: [${label.padEnd(longestLabel)}] ${message}${stringifyValue !== '' ? ` ${stringifyValue}` : ''}`;
});

export const labelledFormat = (labelName = 'App') => {
Expand Down

0 comments on commit f981f9e

Please sign in to comment.