# logger 2.8.0

Small, easy to use and extensible logger which prints beautiful logs.




## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add logger
```
Published: 2026-09-05T17:20:29.963495Z
Expected archive SHA-256: 2a0dc097e7b01d942475bdd552356db2d0f768b05540bd4b2b53f1840f2239a7

Available in cache; verification: upstream_checksum
## Direct dependencies
- clock: ^1.1.0
- meta: ^1.0.0

## Package README (untrusted upstream documentation)
# Logger

[![pub package](https://img.shields.io/pub/v/logger.svg?logo=dart&logoColor=00b9fc)](https://pub.dartlang.org/packages/logger)
[![CI](https://img.shields.io/github/actions/workflow/status/SourceHorizon/logger/dart.yml?branch=main&logo=github-actions&logoColor=white)](https://github.com/SourceHorizon/logger/actions)
[![Last Commits](https://img.shields.io/github/last-commit/SourceHorizon/logger?logo=git&logoColor=white)](https://github.com/SourceHorizon/logger/commits/main)
[![Pull Requests](https://img.shields.io/github/issues-pr/SourceHorizon/logger?logo=github&logoColor=white)](https://github.com/SourceHorizon/logger/pulls)
[![Code size](https://img.shields.io/github/languages/code-size/SourceHorizon/logger?logo=github&logoColor=white)](https://github.com/SourceHorizon/logger)
[![License](https://img.shields.io/github/license/SourceHorizon/logger?logo=open-source-initiative&logoColor=green)](https://github.com/SourceHorizon/logger/blob/main/LICENSE)

Small, easy to use and extensible logger which prints beautiful logs.<br>
Inspired by [logger](https://github.com/orhanobut/logger) for Android.

**Show some ❤️ and star the repo to support the project**

### Resources:

- [Documentation](https://pub.dev/documentation/logger/latest/logger/logger-library.html)
- [Pub Package](https://pub.dev/packages/logger)
- [GitHub Repository](https://github.com/SourceHorizon/logger)

## Getting Started

Just create an instance of `Logger` and start logging:

```dart
var logger = Logger();

logger.d("Logger is working!");
```

Instead of a string message, you can also pass other objects like `List`, `Map` or `Set`.

## Output

![](https://raw.githubusercontent.com/SourceHorizon/logger/main/art/screenshot.png)

# Documentation

## Log level

You can log with different levels:

```dart
logger.t("Trace log");

logger.d("Debug log");

logger.i("Info log");

logger.w("Warning log");

logger.e("Error log", error: 'Test Error');

logger.f("What a fatal log", error: error, stackTrace: stackTrace);
```

To show only specific log levels, you can set:

```dart
Logger.level = Level.warning;
```

This hides all `trace`, `debug` and `info` log events.

## Options

When creating a logger, you can pass some options:

```dart
var logger = Logger(
  filter: null, // Use the default LogFilter (-> only log in debug mode)
  printer: PrettyPrinter(), // Use the PrettyPrinter to format and print log
  output: null, // Use the default LogOutput (-> send everything to console)
);
```

If you use the `PrettyPrinter`, there are more options:

```dart
var logger = Logger(
  printer: PrettyPrinter(
      methodCount: 2, // Number of method calls to be displayed
      errorMethodCount: 8, // Number of method calls if stacktrace is provided
      lineLength: 120, // Width of the output
      colors: true, // Colorful log messages
      printEmojis: true, // Print an emoji for each log message
      // Should each log print contain a timestamp
      dateTimeFormat: DateTimeFormat.onlyTimeAndSinceStart,
  ),
);
```

### Auto detecting

With the `io` package you can auto detect the `lineLength` and `colors` arguments.
Assuming you have imported the `io` package with `import 'dart:io' as io;` you
can auto detect `colors` with `io.stdout.supportsAnsiEscapes` and `lineLength`
with `io.stdout.terminalColumns`.

You should probably do this unless there's a good reason you don't want to
import `io`, for example when using this library on the web.

## LogFilter

The `LogFilter` decides which log events should be shown and which don't.<br>
The default implementation (`DevelopmentFilter`) shows all logs with `level >= Logger.level` while
in debug mode (i.e., running dart with `--enable-asserts`).
In release mode all logs are omitted.

You can create your own `LogFilter` like this:

```dart
class MyFilter extends LogFilter {
  @override
  bool shouldLog(LogEvent event) {
    return true;
  }
}
```

This will show all logs even in release mode. (**NOT** a good idea)

## LogPrinter

The `LogPrinter` creates and formats the output, which is then sent to the `LogOutput`.<br>
You can implement your own `LogPrinter`. This gives you maximum flexibility.

A very basic printer could look like this:

```dart
class MyPrinter extends LogPrinter {
  @override
  List<String> log(LogEvent event) {
    return [event.message];
  }
}
```

If you created a cool `LogPrinter` which might be helpful to others, feel free to open a pull
request.
:)

### Colors

Please note that in some cases ANSI escape sequences do not work under macOS.
These escape sequences are used to colorize the output.
This seems to be related to a Flutter bug that affects iOS builds:
https://github.com/flutter/flutter/issues/64491

However, if you are using a JetBrains IDE (Android Studio, IntelliJ, etc.)
you can make use of
the [Grep Console Plugin](https://plugins.jetbrains.com/plugin/7125-grep-console)
and the [`PrefixPrinter`](/lib/src/printers/prefix_printer.dart)
decorator to achieve colored logs for any logger:

```dart
var logger = Logger(
    printer: PrefixPrinter(PrettyPrinter(colors: false))
);
```

## LogOutput

`LogOutput` sends the log lines to the desired destination.<br>
The default implementation (`ConsoleOutput`) send every line to the system console.

```dart
class ConsoleOutput extends LogOutput {
  @override
  void output(OutputEvent event) {
    for (var line in event.lines) {
      print(line);
    }
  }
}
```

Other provided `LogOutput`s are:

* `FileOutput`/`AdvancedFileOutput`
* `StreamOutput`

Possible future `LogOutput`s could send to Firebase or to Logcat. Feel free to open pull
requests.

# Acknowledgments

This package was originally created by [Simon Choi](https://github.com/simc), with further
development by [Harm Aarts](https://github.com/haarts), greatly enhancing its functionality over
time. 

## Changelog
## 2.8.0

* Expose separate `logEvent` method. Closes
  ([#116](https://github.com/SourceHorizon/logger/issues/116)).

## 2.7.0

* Use `clock` for getting default log event time. Thanks to @alverone
  ([#112](https://github.com/SourceHorizon/logger/pull/112)).

## 2.6.2

* PrettyPrinter: Fixed the showing of internal `package:logger` log lines in the stack trace on
  Flutter/Dart Web. Closes [#102](https://github.com/SourceHorizon/logger/issues/102).
* Lowered the `meta` package version requirement.

## 2.6.1

* AdvancedFileOutput: Fixed race condition while flushing the buffer (`StateError`).
  Closes [#99](https://github.com/SourceHorizon/logger/issues/99), thanks to @sap1tz.

## 2.6.0

* Added log level comparison operators. Thanks to @busslina
  ([#90](https://github.com/SourceHorizon/logger/pull/90)).
* AdvancedFileOutput: Added `fileHeader` and `fileFooter` options.
  Closes [#97](https://github.com/SourceHorizon/logger/issues/97).

## 2.5.0

* AdvancedFileOutput: Added support for custom `fileUpdateDuration`. Thanks to @shlowdy
  ([#86](https://github.com/SourceHorizon/logger/pull/86)).
* README: Fixed outdated LogOutput documentation.

## 2.4.0

* Added pub.dev `topics`. Thanks to @jonasfj
  ([#74](https://github.com/SourceHorizon/logger/pull/74)).
* PrettyPrinter: Added `dateTimeFormat` option (backwards-compatible with `printTime`).
  Fixes [#80](https://github.com/SourceHorizon/logger/issues/80).

## 2.3.0

* AdvancedFileOutput: Added file deletion option. Thanks to @lomby92
  ([#71](https://github.com/SourceHorizon/logger/pull/71)).

## 2.2.0

* Added AdvancedFileOutput. Thanks to @pyciko
  ([#65](https://github.com/SourceHorizon/logger/pull/65)).
* Added missing acknowledgments in README.

## 2.1.0

* Improved README explanation about debug mode. Thanks to @gkuga
  ([#57](https://github.com/SourceHorizon/logger/pull/57)).
* Added web safe export. Fixes [#58](https://github.com/SourceHorizon/logger/issues/58).
* Added `logger.init` to optionally await any `async` `init()` methods.
  Fixes [#61](https://github.com/SourceHorizon/logger/issues/61).

## 2.0.2+1

* Meta update: Updated repository links to https://github.com/SourceHorizon/logger.

## 2.0.2

* Moved the default log level assignment to prevent weird lazy initialization bugs.
  Mitigates [#38](https://github.com/SourceHorizon/logger/issues/38).

## 2.0.1

* Updated README to reflect v2.0.0 log signature change.

## 2.0.0

* Fixed supported platforms list.
* Removed reference to outdated `logger_flutter` project. Thanks to @yangsfang
  ([#32](https://github.com/SourceHorizon/logger/pull/32)).
* Added override capability for logger defaults. Thanks to @yangsfang
  ([#34](https://github.com/SourceHorizon/logger/pull/34)).
* `Level.verbose`, `Level.wtf` and `Level.nothing` have been deprecated and are replaced by
  `Level.trace`, `Level.fatal` and `Level.off`. Additionally `Level.all` has been added.
* PrettyPrinter: Added `levelColors` and `levelEmojis` as constructor parameter.

### Breaking changes

* `log` signature has been changed to closer match dart's developer `log` function and allow for
  future optional parameters.

  Additionally, `time` has been added as an optional named parameter to support providing custom
  timestamps for LogEvents instead of `DateTime.now()`.

  #### Migration:
    * Before:
      ```dart
      logger.e("An error occurred!", error, stackTrace);
      ```
    * After:
      ```dart
      logger.e("An error occurred!", error: error, stackTrace: stackTrace);
      ```
* `init` and `close` methods of `LogFilter`, `LogOutput` and `LogPrinter` are now async along with
  `Logger.close()`. (Fixes FileOutput)
* LogListeners are now called on every LogEvent independent of the filter.
* PrettyPrinter: `includeBox` is now private.
* PrettyPrinter: `errorMethodCount` is now only considered if an error has been provided. Otherwise
  `methodCount` is used.
* PrettyPrinter: Static `levelColors` and `levelEmojis` have been renamed to `defaultLevelColors`
  and `defaultLevelEmojis` and are used as fallback for their respective constructor parameters.
* Levels are now sorted by their respective value instead of the enum index (Order didn't change).

## 1.4.0

* Bumped upper SDK constraint to `<4.0.0`.
* Added `excludePaths` to PrettyPrinter. Thanks to @Stitch-Taotao
  ([#13](https://github.com/SourceHorizon/logger/pull/13)).
* Removed background color for `Level.error` and `Level.wtf` to improve readability.
* Improved PrettyPrinter documentation.
* Corrected README notice about ANSI colors.

## 1.3.0

* Fixed stackTrace count when using `stackTraceBeginIndex`.
  Addresses [#114](https://github.com/simc/logger/issues/114).
* Added proper FileOutput stub. Addresses [#94](https://github.com/simc/logger/issues/94).
* Added `isClosed`. Addresses [#130](https://github.com/simc/logger/issues/130).
* Added `time` to LogEvent.
* Added `error` handling to LogfmtPrinter.

## 1.2.2

* Fixed conditional LogOutput export. Credits to
  @ChristopheOosterlynck [#4](https://github.com/SourceHorizon/logger/pull/4).

## 1.2.1

* Reverted `${this}` interpolation and added linter
  ignore. [#1](https://github.com/SourceHorizon/logger/issues/1)

## 1.2.0

* Added origin LogEvent to OutputEvent. Addresses [#133](https://github.com/simc/logger/pull/133).
* Re-added LogListener and OutputListener (Should restore compatibility with logger_flutter).
* Replaced pedantic with lints.

## 1.1.0

* Enhance boxing control with PrettyPrinter. Credits to @timmaffett
* Add trailing new line to FileOutput. Credits to @narumishi
* Add functions as a log message. Credits to @smotastic

## 1.0.0

* Stable nullsafety

## 1.0.0-nullsafety.0

* Convert to nullsafety. Credits to @DevNico

## 0.9.4

* Remove broken platform detection.

## 0.9.3

* Add `MultiOutput`. Credits to @gmpassos.
* Handle browser Dart stacktraces in PrettyPrinter. Credits to @gmpassos.
* Add platform detection. Credits to @gmpassos.
* Catch output exceptions. Credits to @gmpassos.
* Several documentation fixes. Credits to @gmpassos.

## 0.9.2

* Add `PrefixPrinter`. Credits to @tkutcher.
* Add `HybridPrinter`. Credits to @tkutcher.

## 0.9.1

* Fix logging output for Flutter Web. Credits to @nateshmbhat and @Cocotus.

## 0.9.0

* Remove `OutputCallback` and `LogCallback`
* Rename `SimplePrinter`s argument `useColor` to `colors`
* Rename `DebugFilter` to `DevelopmentFilter`

## 0.8.3

* Add LogfmtPrinter
* Add colored output to SimplePrinter

## 0.8.2

* Add StreamOutput

## 0.8.1

* Deprecate callbacks

## 0.8.0

* Fix SimplePrinter showTime #12
* Remove buffer field
* Update library structure (thanks @marcgraub!)

## 0.7.0+2

* Remove screenshot

## 0.7.0+1

* Fix pedantic

## 0.7.0

* Added `ProductionFilter`, `FileOutput`, `MemoryOutput`, `SimplePrinter`
* Breaking: Changed `LogFilter`, `LogPrinter` and `LogOutput`

## 0.6.0

* Added option to output timestamp
* Added option to disable color
* Added `LogOutput`
* Behaviour change of `LogPrinter`
* Remove dependency

## 0.5.0

* Added emojis
* `LogFilter` is a class now

## 0.4.0

* First version of the new logger







 
