LogRecord constructor

LogRecord(
  1. LogLevel level,
  2. String message, {
  3. String? loggerName,
  4. DateTime? time,
  5. Object? error,
  6. StackTrace? stackTrace,
})

A LogRecord represents a single logging event captured by the logging system.

It holds metadata such as the log level, message, timestamp, error object, and stack trace. This structure allows loggers to format and route logs consistently and meaningfully.

This is particularly useful in diagnostic tools, analytics, and structured log processing.

Example usage:

final record = LogRecord(
  LogLevel.warning,
  'Something suspicious happened',
  loggerName: 'AuthService',
  error: InvalidFormatException('Invalid token'),
  stackTrace: StackTrace.current,
);
print(record);

Creates a new instance of LogRecord.

If time is not provided, it defaults to the current time.

Implementation

LogRecord(
  this.level,
  this.message, {
  this.loggerName,
  DateTime? time,
  this.error,
  this.stackTrace,
}) : time = time ?? DateTime.now();