Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

TRIA-535 - Add second and millisecond #9

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dist/logger-factory-generator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const moment = require("moment");
const DATETIME_FORMAT = 'YYYY-MM-DD HH:mm:ss.SSS Z';
function prepareErrorToLog(error, messages = []) {
if (messages.length) {
error.message = `${error.message} :: ${messages.join(',')}`;
Expand All @@ -24,7 +25,7 @@ exports.loggerFactoryGenerator = ({ winston, consoleTransportClass, sentryTransp
return Object.assign(info, {
application: config.logstash.application || 'gupy',
pid: process.pid,
time: moment.utc().format('YYYY-MM-DD HH:mm Z'),
time: moment.utc().format(DATETIME_FORMAT),
});
});
transports.push(new logstashTransportClass({
Expand All @@ -35,7 +36,7 @@ exports.loggerFactoryGenerator = ({ winston, consoleTransportClass, sentryTransp
}));
}
const logger = winston.createLogger({
format: winston.format.printf(error => `${moment.utc().format('YYYY-MM-DD HH:mm Z')} [${error.level}]: ${error.message}`),
format: winston.format.printf(error => `${moment.utc().format(DATETIME_FORMAT)} [${error.level}]: ${error.message}`),
transports,
exitOnError: false,
});
Expand Down
1 change: 0 additions & 1 deletion dist/logger-factory-generator.test.d.ts

This file was deleted.

107 changes: 0 additions & 107 deletions dist/logger-factory-generator.test.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/logger-factory-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('gupy-logger', () => {
expect(lastLogstashLog.message).to.equal('any info');
expect(lastLogstashLog.level).to.equal('info');

expect(lastConsoleLog[symbolMessage]).to.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2} \+\d{2}:\d{2} \[info]: any info/);
expect(lastConsoleLog[symbolMessage]).to.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3} \+\d{2}:\d{2} \[info]: any info/);
expect(lastConsoleLog[symbolLevel]).to.equal('info');
});

Expand All @@ -100,7 +100,7 @@ describe('gupy-logger', () => {
expect(lastLogstashLog.message).to.equal('any warn');
expect(lastLogstashLog.level).to.equal('warn');

expect(lastConsoleLog[symbolMessage]).to.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2} \+\d{2}:\d{2} \[warn]: any warn/);
expect(lastConsoleLog[symbolMessage]).to.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3} \+\d{2}:\d{2} \[warn]: any warn/);
expect(lastConsoleLog[symbolLevel]).to.equal('warn');
});

Expand All @@ -117,11 +117,11 @@ describe('gupy-logger', () => {
expect(lastLogstashLog.message).to.equal('any error');

expect(lastSentryLog).to.deep.equal(expectedLog);
expect(lastSentryLog[symbolMessage]).to.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2} \+\d{2}:\d{2} \[error]: any error/);
expect(lastSentryLog[symbolMessage]).to.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3} \+\d{2}:\d{2} \[error]: any error/);
expect(lastSentryLog[symbolLevel]).to.equal('error');

expect(lastConsoleLog).to.be.deep.equal(expectedLog);
expect(lastConsoleLog[symbolMessage]).to.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2} \+\d{2}:\d{2} \[error]: any error/);
expect(lastConsoleLog[symbolMessage]).to.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3} \+\d{2}:\d{2} \[error]: any error/);
expect(lastConsoleLog[symbolLevel]).to.equal('error');
});
});
6 changes: 4 additions & 2 deletions src/logger-factory-generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Logger} from 'winston';
import * as moment from 'moment';

const DATETIME_FORMAT = 'YYYY-MM-DD HH:mm:ss.SSS Z';

declare interface IConfig {
sentry: {
enabled: boolean,
Expand Down Expand Up @@ -48,7 +50,7 @@ export const loggerFactoryGenerator = ({winston, consoleTransportClass, sentryTr
return Object.assign(info, {
application: config.logstash.application || 'gupy',
pid: process.pid,
time: moment.utc().format('YYYY-MM-DD HH:mm Z'),
time: moment.utc().format(DATETIME_FORMAT),
});
});

Expand All @@ -66,7 +68,7 @@ export const loggerFactoryGenerator = ({winston, consoleTransportClass, sentryTr

const logger: Logger = winston.createLogger({
format: winston.format.printf(
error => `${moment.utc().format('YYYY-MM-DD HH:mm Z')} [${error.level}]: ${error.message}`,
error => `${moment.utc().format(DATETIME_FORMAT)} [${error.level}]: ${error.message}`,
),
transports,
exitOnError: false,
Expand Down