formats a log entry as a json string. includes all entry properties and conditionally adds metadata and args if present.
the log entry to format
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"]}
formatter that outputs log entries as json strings. useful for structured logging and machine-readable output.
Example: basic usage