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:
parent
e5624e173c
commit
cf1b46cc59
7 changed files with 27 additions and 28 deletions
6
.changeset/dry-shoes-report.md
Normal file
6
.changeset/dry-shoes-report.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
'@verdaccio/logger-commons': patch
|
||||
'@verdaccio/logger-prettify': patch
|
||||
---
|
||||
|
||||
fix: log spacing depending on the FORMAT and COLORS options
|
|
@ -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(
|
||||
|
|
|
@ -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, ' ');
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue