Skip to content

Commit

Permalink
feat(logging): track log record creation times (#3336)
Browse files Browse the repository at this point in the history
Refs #3197
  • Loading branch information
char0n committed Oct 30, 2023
1 parent 06960c4 commit a4e2357
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/apidom-logging/src/LogRecord.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type LoggingLevel from './LoggingLevel';
import { getLevelName } from './LoggingLevel';

const startTime: number = Date.now();

export interface LogRecordInstance<T extends Error = Error> {
readonly name: string;
readonly message: string;
Expand Down Expand Up @@ -31,6 +33,12 @@ class LogRecord<T extends Error = Error> implements LogRecordInstance<T> {

public readonly message: string;

public readonly created: number;

public readonly msecs: number;

public readonly relativeCreated: number;

public readonly process?: number;

public readonly processName?: string;
Expand All @@ -46,11 +54,16 @@ class LogRecord<T extends Error = Error> implements LogRecordInstance<T> {
error?: T,
extra?: Record<string, unknown>,
) {
const created = Date.now();

this.name = name;
this.levelno = level;
this.levelname = getLevelName(level);
this.message = message;
this.error = error;
this.created = Math.floor(created / 1000);
this.msecs = created - this.created * 1000;
this.relativeCreated = created - startTime;

if (globalThis.process?.pid) {
this.process = globalThis.process.pid;
Expand Down

0 comments on commit a4e2357

Please sign in to comment.