mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-20 22:52:46 -05:00
631abe1ac1
* refactor logger module * Update index.ts
23 lines
687 B
TypeScript
23 lines
687 B
TypeScript
import dayjs from 'dayjs';
|
|
import _ from 'lodash';
|
|
|
|
export const FORMAT_DATE = 'YYYY-MM-DD HH:mm:ss';
|
|
export const CUSTOM_PAD_LENGTH = 1;
|
|
|
|
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, ' ');
|
|
}
|
|
|
|
export function formatLoggingDate(time: number, message: string): string {
|
|
const timeFormatted = dayjs(time).format(FORMAT_DATE);
|
|
|
|
return `[${timeFormatted}]${message}`;
|
|
}
|