Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

force the foreground color to white for the error background #137

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
15ff26a
Updated repository links and added acknowledgment
Bungeefan Feb 8, 2023
e6d84b6
Revert "Remove callbacks"
Bungeefan Feb 8, 2023
bf2c13c
Replaced pedantic with lints
Bungeefan Feb 8, 2023
77cdd82
Fixed doc reference
Bungeefan Feb 8, 2023
a6970d9
Added origin LogEvent to OutputEvent, addresses https://github.com/si…
Bungeefan Feb 8, 2023
68767d8
Updated dart.yml
Bungeefan Feb 8, 2023
45761a6
Fixed CI shield
Bungeefan Feb 8, 2023
a276e6f
Removed obsolete .travis.yml
Bungeefan Feb 15, 2023
0e58c14
Bumped version to 1.2.0
Bungeefan Feb 22, 2023
bf4e655
Reverted `${this}` interpolation and added linter ignore, fixes #1
Bungeefan Feb 23, 2023
2f940c5
Bumped version to 1.2.1
Bungeefan Feb 23, 2023
7627472
Added CI run for Dart SDK 2.17.0
Bungeefan Feb 23, 2023
9663000
Expose LogOutput class unconditionally
Feb 23, 2023
17675e3
Fixed linter warning, closes #3
Bungeefan Feb 23, 2023
9e9dbdb
Bumped version to 1.2.2
Bungeefan Feb 23, 2023
57f4ec7
Added `continue-on-error` to run CI for all specified SDK versions
Bungeefan Feb 23, 2023
0cc96e2
Added `error` handling to LogfmtPrinter
Bungeefan Feb 25, 2023
9a8da9c
Fixed test imports (removed /src imports)
Bungeefan Feb 25, 2023
f7f4779
Fixed stackTrace count when using `stackTraceBeginIndex`, addresses h…
Bungeefan Feb 25, 2023
1d8d47d
Added `time` to LogEvent
Bungeefan Feb 25, 2023
6f35b50
Added `isClosed`, addresses https://github.com/simc/logger/issues/130
Bungeefan Feb 25, 2023
985e862
Removed obsolete linter ignore
Bungeefan Feb 25, 2023
ea8c9c4
Replaced `continue-on-error` with `fail-fast`, continues 57f4ec7e82cb…
Bungeefan Feb 26, 2023
8e3fbea
Added proper FileOutput stub, addresses https://github.com/simc/logge…
Bungeefan Feb 27, 2023
d437a0c
Bumped version to 1.3.0
Bungeefan Mar 12, 2023
2a047d4
Simplified sdk constraint
Bungeefan May 10, 2023
8a7a81b
Formatted
Bungeefan May 15, 2023
d672c9c
Corrected ANSI notice
Bungeefan May 15, 2023
2ec1283
add custom excludePaths properties in pretty_printer
Stitch-Taotao Mar 4, 2023
77109cc
Merge pull request #1 from Bungeefan/master
shirne Jun 3, 2023
a635cbd
force the foreground color to white for the error background
shirne Apr 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
name: Dart CI
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# See documentation here:
# https://github.com/dart-lang/setup-dart/blob/main/README.md

name: Dart

on:
push:
branches: [ master ]
branches: [ "master" ]
pull_request:
branches: [ master ]
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [ stable, 2.17.0 ]
steps:
- uses: actions/checkout@v3

container:
image: google/dart:2.12
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}

steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: pub get
- name: Format code
run: dartfmt -n --set-exit-if-changed .
- name: Static analyze project
run: dartanalyzer --fatal-infos --fatal-warnings .
- name: Run tests
run: pub run test
- name: Install dependencies
run: dart pub get

# Uncomment this step to verify the use of 'dart format' on each commit.
- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: Analyze project source
run: dart analyze --fatal-infos

# Your project will need to have tests in test/ and a dependency on
# package:test for this step to succeed. Note that Flutter projects will
# want to change this to 'flutter test'.
- name: Run tests
run: dart test
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

31 changes: 29 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
## 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/Bungeefan/logger/pull/4).

## 1.2.1

- Reverted `${this}` interpolation and added linter
ignore. [#1](https://github.com/Bungeefan/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
Expand All @@ -22,7 +49,7 @@
## 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.

Expand All @@ -45,7 +72,7 @@
- Fix SimplePrinter showTime #12
- Remove buffer field
- Update library structure (thanks @marcgraub!)

## 0.7.0+1
- Added `ProductionFilter`, `FileOutput`, `MemoryOutput`, `SimplePrinter`
- Breaking: Changed `LogFilter`, `LogPrinter` and `LogOutput`
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2019 Simon Leier
Copyright (c) 2023 Severin Hamader

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
98 changes: 45 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# 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/workflow/status/leisim/logger/Dart%20CI/master?logo=github-actions&logoColor=white)](https://github.com/leisim/logger/actions)
[![Last Commits](https://img.shields.io/github/last-commit/leisim/logger?logo=git&logoColor=white)](https://github.com/leisim/logger/commits/master)
[![Pull Requests](https://img.shields.io/github/issues-pr/leisim/logger?logo=github&logoColor=white)](https://github.com/leisim/logger/pulls)
[![Code size](https://img.shields.io/github/languages/code-size/leisim/logger?logo=github&logoColor=white)](https://github.com/leisim/logger)
[![License](https://img.shields.io/github/license/leisim/logger?logo=open-source-initiative&logoColor=green)](https://github.com/leisim/logger/blob/master/LICENSE)
[![CI](https://img.shields.io/github/actions/workflow/status/Bungeefan/logger/dart.yml?branch=master&logo=github-actions&logoColor=white)](https://github.com/Bungeefan/logger/actions)
[![Last Commits](https://img.shields.io/github/last-commit/Bungeefan/logger?logo=git&logoColor=white)](https://github.com/Bungeefan/logger/commits/master)
[![Pull Requests](https://img.shields.io/github/issues-pr/Bungeefan/logger?logo=github&logoColor=white)](https://github.com/Bungeefan/logger/pulls)
[![Code size](https://img.shields.io/github/languages/code-size/Bungeefan/logger?logo=github&logoColor=white)](https://github.com/Bungeefan/logger)
[![License](https://img.shields.io/github/license/Bungeefan/logger?logo=open-source-initiative&logoColor=green)](https://github.com/Bungeefan/logger/blob/master/LICENSE)


NOTICE: This repo is NOT LONGER leading! The new repo is here: https://github.com/Bungeefan/logger
Expand All @@ -16,13 +16,15 @@ 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/leisim/logger)
- [GitHub Repository](https://github.com/Bungeefan/logger)

## Getting Started

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

```dart
var logger = Logger();

Expand All @@ -33,7 +35,7 @@ Instead of a string message, you can also pass other objects like `List`, `Map`

## Output

![](https://raw.githubusercontent.com/leisim/logger/master/art/screenshot.png)
![](https://raw.githubusercontent.com/Bungeefan/logger/master/art/screenshot.png)

# Documentation

Expand Down Expand Up @@ -80,32 +82,35 @@ 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
printTime: false // Should each log print contain a timestamp
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
printTime: false // Should each log print contain a timestamp
),
);
```

### 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 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
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. In release mode all logs are omitted.
The default implementation (`DevelopmentFilter`) shows all logs with `level >= Logger.level` while
in debug mode.
In release mode all logs are omitted.

You can create your own `LogFilter` like this:

```dart
class MyFilter extends LogFilter {
@override
Expand All @@ -114,15 +119,16 @@ class MyFilter extends LogFilter {
}
}
```
This will show all logs even in release mode. (**NOT** a good idea)

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
Expand All @@ -132,22 +138,26 @@ class MyPrinter extends LogPrinter {
}
```

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

### Colors

Please note that all IDEs (VSCode, XCode, Android Studio, IntelliJ) do not
support ANSI escape sequences in their terminal outputs. These escape sequences
are used to color output. If using such an IDE do not configure colored output.
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 achieved colored logs for any logger:
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))
printer: PrefixPrinter(PrettyPrinter(colors: false))
);
```

Expand All @@ -167,33 +177,15 @@ class ConsoleOutput extends LogOutput {
}
```

Possible future `LogOutput`s could send to a file, firebase or to Logcat. Feel free to open pull requests.

Possible future `LogOutput`s could send to a file, firebase or to Logcat. Feel free to open pull
requests.

## logger_flutter extension

The [logger_flutter](https://pub.dev/packages/logger_flutter) package is an extension for logger. You can add it to any Flutter app. Just shake the phone to show the console.
The [logger_flutter](https://pub.dev/packages/logger_flutter) package is an extension for logger.
You can add it to any Flutter app.
Just shake the phone to show the console.

# Acknowledgments

## MIT License
```
Copyright (c) 2019 Simon Leier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
This package was originally created by [Simon Choi](https://github.com/simc).
5 changes: 4 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
25 changes: 10 additions & 15 deletions lib/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@
library logger;

export 'src/ansi_color.dart';

export 'src/filters/development_filter.dart';
export 'src/filters/production_filter.dart';

export 'src/log_filter.dart';
export 'src/log_output.dart';
export 'src/log_printer.dart';
export 'src/logger.dart';
export 'src/outputs/console_output.dart';
export 'src/outputs/stream_output.dart';
export 'src/outputs/file_output_stub.dart'
if (dart.library.io) 'src/outputs/file_output.dart';
export 'src/outputs/memory_output.dart';
export 'src/outputs/multi_output.dart';

export 'src/printers/pretty_printer.dart';
export 'src/printers/logfmt_printer.dart';
export 'src/printers/simple_printer.dart';
export 'src/outputs/stream_output.dart';
export 'src/printers/hybrid_printer.dart';
export 'src/printers/logfmt_printer.dart';
export 'src/printers/prefix_printer.dart';

export 'src/log_output.dart'
if (dart.library.io) 'src/outputs/file_output.dart';

export 'src/log_filter.dart';
export 'src/log_output.dart';
export 'src/log_printer.dart';
export 'src/logger.dart';
export 'src/printers/pretty_printer.dart';
export 'src/printers/simple_printer.dart';
1 change: 1 addition & 0 deletions lib/src/ansi_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AnsiColor {

String call(String msg) {
if (color) {
// ignore: unnecessary_brace_in_string_interps
return '${this}$msg$ansiDefault';
} else {
return msg;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/filters/development_filter.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:logger/src/logger.dart';
import 'package:logger/src/log_filter.dart';
import 'package:logger/src/logger.dart';

/// Prints all logs with `level >= Logger.level` while in development mode (eg
/// when `assert`s are evaluated, Flutter calls this debug mode).
Expand Down
2 changes: 1 addition & 1 deletion lib/src/filters/production_filter.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:logger/src/logger.dart';
import 'package:logger/src/log_filter.dart';
import 'package:logger/src/logger.dart';

/// Prints all logs with `level >= Logger.level` even in production.
class ProductionFilter extends LogFilter {
Expand Down
1 change: 1 addition & 0 deletions lib/src/log_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:logger/src/logger.dart';
/// Every implementation should consider [Logger.level].
abstract class LogFilter {
Level? level;

void init() {}

/// Is called every time a new log message is sent and decides if
Expand Down
Loading