lily
    Preparing search index...

    formatter that outputs log entries as json strings. useful for structured logging and machine-readable output.

    const formatter = new JsonFormatter();
    const json = formatter.format(logEntry);
    console.log(json);
    // {"timestamp":"2024-01-01T12:00:00.000Z","level":2,"scope":["app"],"message":"hello"}
    Index

    Constructors

    Methods

    Constructors

    Methods

    • formats a log entry as a json string. includes all entry properties and conditionally adds metadata and args if present.

      Parameters

      Returns string

      json string representation of the log entry

      const entry = {
      level: LogLevel.INFO,
      message: 'user action',
      timestamp: new Date(),
      scope: ['auth', 'login'],
      args: ['user123'],
      metadata: { userId: 123 }
      };

      const json = formatter.format(entry);
      // {"timestamp":"2024-01-01T12:00:00.000Z","level":2,"scope":["auth","login"],"message":"user action","metadata":{"userId":123},"args":["user123"]}