UNPKG

@nestjs/common

Version:

Decorators, pipes, exceptions and utilities for NestJS applications: @Controller(), @Injectable(), @Body(), ValidationPipe, HttpException and more.

25 lines (24 loc) • 724 B
const dateTimeFormatter = new Intl.DateTimeFormat(undefined, { year: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', day: '2-digit', month: '2-digit', }); let lastFormattedSecond; let lastFormattedTimestamp = ''; /** * Formats the current time for a log line. The format stops at seconds, so * the string is formatted once per second and reused by the lines logged * within it. */ export function formatLogTimestamp() { const now = Date.now(); const second = Math.floor(now / 1000); if (second !== lastFormattedSecond) { lastFormattedTimestamp = dateTimeFormatter.format(now); lastFormattedSecond = second; } return lastFormattedTimestamp; }