comon_logger_file 0.1.0 copy "comon_logger_file: ^0.1.0" to clipboard
comon_logger_file: ^0.1.0 copied to clipboard

File-based log handler for comon_logger with log rotation.

comon_logger_file #

File-based log handler for comon_logger with automatic log rotation.

Setup #

import 'package:comon_logger/comon_logger.dart';
import 'package:comon_logger_file/comon_logger_file.dart';

final fileHandler = FileLogHandler(
  directory: '/path/to/logs',
  maxFileSize: 5 * 1024 * 1024, // 5 MB
  maxFiles: 5,
);
await fileHandler.init();
Logger.root.addHandler(fileHandler);

Features #

  • Automatic rotation: When a log file exceeds maxFileSize, it rotates to comon_log_1.txt, comon_log_2.txt, etc.
  • File limit: Old files beyond maxFiles are deleted automatically.
  • JSON mode: Set writeAsJson: true to write one JSON object per line (compatible with LogRecord.fromJson()).
  • Custom formatter: Pass any LogFormatter instance. Defaults to SimpleLogFormatter.
  • Append on restart: Re-initializing appends to the existing file.

Configuration #

Parameter Default Description
directory required Directory path for log files
baseFileName 'comon_log' Base name (without extension)
extension '.txt' File extension
maxFileSize 5 MB Max size before rotation
maxFiles 5 Max rotated files to keep
writeAsJson false Write records as JSON
filter AllPassLogFilter Filter for this handler
formatter SimpleLogFormatter Text formatter

Lifecycle #

await fileHandler.init();     // open file
// ... logging happens ...
await fileHandler.flush();    // ensure writes are on disk
await fileHandler.close();    // release resources
0
likes
0
points
261
downloads

Publisher

verified publisherserezhia.ru

Weekly Downloads

File-based log handler for comon_logger with log rotation.

Homepage
Repository (GitHub)
View/report issues

Topics

#logging #file #log-rotation

License

unknown (license)

Dependencies

comon_logger

More

Packages that depend on comon_logger_file