로거 패키지는 플러터 애플리케이션을 위한 가벼우면서도 사용자 정의 가능한 로깅 솔루션입니다. 여러 로그 레벨, 구조화된 출력 및 간편한 통합을 지원하며 깔끔하고 읽기 쉬우며 아름답게 포맷된 로그를 제공합니다. 디버깅과 모니터링을 위해 설계되었으며, 모든 플랫폼에서 애플리케이션 동작을 효율적으로 추적하는 데 도움을 줍니다. 확장 가능하여 사용자 지정 포맷터와 출력 대상을 설정할 수 있습니다. 최소한의 크기와 직관적인 API 덕분에 개발 및 생산 환경 모두에 적합합니다.
사용 사례
응용 프로그램 흐름 디버깅
런타임 동작 모니터링
오류 및 경고 추적
생산 앱에서의 로깅
CI/CD 파이프라인과의 통합
주요 기능
아름답게 형식화된 로그
확장 가능한 포맷터 시스템
여러 로그 레벨
크로스 플랫폼 지원
간단한 API
사용자 정의 출력 대상
적합한 대상
간단한 로깅을 원하는 개발자
구조화된 로그가 필요한 팀
디버그 시각화가 필요한 앱
로그 기록이 필요한 프로덕션 환경
크로스 플랫폼 Flutter 프로젝트
고려 사항
생산 사용을 위해 구성이 필요할 수 있습니다
관리되지 않으면 자세한 출력은 성능에 영향을 줄 수 있습니다
제한된 내장 필터 옵션
복잡한 로그 저장 또는 분석을 위한 것이 아님
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Logger
Small, easy to use and extensible logger which prints beautiful logs.
Inspired by logger for Android.
Show some ❤️ and star the repo to support the project
When creating a logger, you can pass some options:
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:
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.
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.
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.
You can implement your own LogPrinter. This gives you maximum flexibility.
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
and the PrefixPrinter
decorator to achieve colored logs for any logger:
var logger = Logger(
printer: PrefixPrinter(PrettyPrinter(colors: false))
);
LogOutput
LogOutput sends the log lines to the desired destination.
The default implementation (ConsoleOutput) send every line to the system console.
classConsoleOutputextendsLogOutput{
@overridevoidoutput(OutputEvent event) {
for (var line in event.lines) {
print(line);
}
}
}
Other provided LogOutputs are:
FileOutput/AdvancedFileOutput
StreamOutput
Possible future LogOutputs could send to Firebase or to Logcat. Feel free to open pull
requests.
Acknowledgments
This package was originally created by Simon Choi, with further
development by Harm Aarts, greatly enhancing its functionality over
time.