0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00

fix: log spacing depending on the FORMAT and COLORS options (#4631)

* fix: Bad log spacing depending on the FORMAT and COLORS options used

fixes: #4630

inserted a space between the timestamp and the message when logging timestamped messages.

* fix: Bad log spacing depending on the FORMAT and COLORS options used

fixes: #4630

removed padding of an unnecessary space (at the start or end of the log string, depending on whether colors are enabled).

* remove padLeft, update tests

* update logger-commons tests

---------

Co-authored-by: Marc Bernard <marc@marcbernardtools.com>
This commit is contained in:
Michael Ryan 2024-06-01 12:35:06 -07:00 committed by GitHub
parent e5624e173c
commit cf1b46cc59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 27 additions and 28 deletions

View file

@ -0,0 +1,6 @@
---
'@verdaccio/logger-commons': patch
'@verdaccio/logger-prettify': patch
---
fix: log spacing depending on the FORMAT and COLORS options

View file

@ -3,7 +3,7 @@ import { inspect } from 'util';
import { LevelCode, calculateLevel, levelsColors, subSystemLevels } from './levels';
import { PrettyOptionsExtended } from './types';
import { formatLoggingDate, isObject, padLeft, padRight } from './utils';
import { formatLoggingDate, isObject, padRight } from './utils';
let LEVEL_VALUE_MAX = 0;
for (const l in levelsColors) {
@ -68,11 +68,11 @@ function getMessage(debugLevel, msg, sub, templateObjects, hasColors: boolean) {
`${subSystemType} ${finalMessage}`
)}`;
return padLeft(logString);
return logString;
}
const logString = `${padRight(debugLevel, LEVEL_VALUE_MAX)}${subSystemType} ${finalMessage}`;
return padRight(logString);
return logString;
}
export function printMessage(

View file

@ -8,10 +8,6 @@ export function isObject(obj: unknown): boolean {
return _.isObject(obj) && _.isNull(obj) === false && _.isArray(obj) === false;
}
export function padLeft(message: string) {
return message.padStart(message.length + CUSTOM_PAD_LENGTH, ' ');
}
export function padRight(message: string, max = message.length + CUSTOM_PAD_LENGTH) {
return message.padEnd(max, ' ');
}

View file

@ -1,4 +1,4 @@
import { formatLoggingDate, padLeft, padRight } from '../src/utils';
import { formatLoggingDate, padRight } from '../src/utils';
describe('formatLoggingDate', () => {
test('basic', () => {
@ -14,7 +14,4 @@ describe('pad', () => {
test('pad right 2', () => {
expect(padRight('message right')).toEqual('message right ');
});
test('pad left', () => {
expect(padLeft('message left')).toEqual(' message left');
});
});