flutter_logs는 Flutter 애플리케이션을 위한 포괄적인 파일 기반 로깅 프레임워크로, ELK 스택(Elasticsearch, Logstash, Kibana)을 지원하여 세부적이고 구조화된 로깅을 가능하게 합니다. 개발자는 로그를 로컬 파일에 저장할 수 있어 앱의 동작을 시간이 지남에 따라 디버깅하고 분석하기 쉬워집니다. 이 패키지는 Android 및 iOS 플랫폼을 모두 지원하며, 구성 가능한 로그 레벨, 회전 및 보존 정책을 제공합니다. 생산 환경에서의 디버깅과 모니터링에 이상적이며, 지속 가능한 검색 가능한 로그 파일을 통해 앱 성능과 오류에 대한 가시성을 향상시킵니다.
사용 사례
생산 문제 디버깅
시간이 지남에 따라 앱 동작 모니터링
중앙 집중형 로깅을 위한 ELK 스택 통합
크래시 패턴 분석
사용자 고유의 오류 시퀀스 추적
주요 기능
파일 기반 로그 저장
ELK 스택 호환성
사용자 정의 로그 레벨
로그 파일 회전 및 보관
크로스 플랫폼 지원 (Android 및 iOS)
pubspec를 통한 간편한 통합
적합한 대상
지속적인 로깅이 필요한 개발자
중앙 집중형 로그 분석을 사용하는 팀
세부적인 오류 추적을 필요로 하는 앱
생산급 디버깅
장기 성능 모니터링
고려 사항
수동 로그 파일 관리가 필요합니다
앱 저장 공간 사용량이 증가할 수 있습니다
최적의 성능을 위해 적절한 구성이 필요합니다
실시간 스트리밍 로그에 적합하지 않습니다
로그 집약 도구와 가장 잘 어울림
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
flutter_logs
A file based advanced logging framework for Flutter Apps (Android & iOS).
Overview
Flutter Logs provides quick & simple file based logging solution. All logs are saved to files in storage path provided. A new log file is created every hour on a new log event. These logs can be filtered and sorted easily. Logs can easily be exported as zip file base on filter type. PLogs also provide functionality to arrange data logs into a predefined directory structure. Custom logs can be used for a specific events based logging within the app. Logs can be saved as encrypted for security purposes.
Flutter logs can work with Logstash by writing JSON delimited logs to log files. The format is based on ELK schema. You can also send logs in real-time to server using MQTT. MQTT configuration can be applied on Logstash to receive & view logs on kibana dashboard.
Options 1
Options 2
Read more about flutter_logs usage on this Medium article:
How log files are arranged on disk. See values below.
timeStampFormat
TimeStampFormat
required
Timestamp format appended to each log entry. See values below.
logFileExtension
LogFileExtension
required
File extension for log files. See values below.
logLevelsEnabled
List<LogLevel>?
null (all)
Which log levels are written to file. Omit to enable all levels.
logTypesEnabled
List<String>?
null
Names of custom log-type files (used with logToFile).
logsRetentionPeriodInDays
int
14
Log files older than this are deleted automatically.
zipsRetentionPeriodInDays
int
3
Exported zip files older than this are deleted automatically.
autoDeleteZipOnExport
bool
false
Delete the zip file from the export directory after a successful export.
autoClearLogs
bool
true
Automatically clear log files when retention period expires.
autoExportErrors
bool
true
Automatically export ERROR/SEVERE logs when they occur.
encryptionEnabled
bool
false
Encrypt log files on disk. Requires encryptionKey.
encryptionKey
String
""
AES encryption key. Only used when encryptionEnabled is true.
logSystemCrashes
bool
true
Capture uncaught exceptions and log them automatically.
isDebuggable
bool
true
Print internal plugin debug messages to the console.
debugFileOperations
bool
true
Log file read/write operations to the console for tracing.
attachTimeStamp
bool
true
Prepend a timestamp to each log entry.
attachNoOfFiles
bool
true
Append the current file count to each log entry.
zipFilesOnly
bool
false
Export logs as a zip even when a single file would suffice.
logsWriteDirectoryName
String
""
Subdirectory name inside app storage where logs are written.
logsExportZipFileName
String
""
Custom name for the exported zip file (without extension).
logsExportDirectoryName
String
""
Subdirectory inside app storage where exported zips are placed.
singleLogFileSize
int
2
Maximum size of a single log file in MB before a new one is created.
enabled
bool
true
Master switch — set to false to disable all logging without changing config.
forceWriteLogs
bool
true
Write logs immediately even when the internal buffer is not full.
enableLogsWriteToFile
bool
true
Write log entries to files. Disable to log to console only.
formatType
FormatType
FORMAT_CURLY
Structure of each log entry. See values below.
customFormatOpen
String
" "
Opening delimiter used when formatType is FORMAT_CUSTOM.
customFormatClose
String
" "
Closing delimiter used when formatType is FORMAT_CUSTOM.
logFilesLimit
int
100
Maximum number of log files kept on disk before the oldest are removed.
nameForEventDirectory
String
""
Directory name for event logs. Used when directoryStructure is FOR_EVENT.
autoExportLogTypes
List<String>?
null
Log-type names that are exported automatically on a timer.
autoExportLogTypesPeriod
int
0
Interval in minutes between automatic exports. 0 disables the timer.
csvDelimiter
String
""
Column separator used when formatType is FORMAT_CSV.
exportFormatted
bool
true
Apply formatting rules when exporting (pretty-print).
exportFileNamePreFix
String
""
String prepended to the exported zip file name.
exportFileNamePostFix
String
""
String appended to the exported zip file name.
backpressureConfig
BackpressureConfig?
null
Queue and per-level quota settings for high-volume logging. See Backpressure below.
redactionConfig
RedactionConfig?
null
PII masking rules applied before writing each log entry. See Redaction below.
Enum Values
DirectoryStructure
Value
Description
FOR_DATE
One directory per date, one file per hour inside it.
FOR_EVENT
All logs grouped into a single named event directory (nameForEventDirectory).
SINGLE_FILE_FOR_DAY
One log file per day.
TimeStampFormat
Value
Example output
DATE_FORMAT_1
2024-01-15
DATE_FORMAT_2
15-01-2024
TIME_FORMAT_FULL_JOINED
150120241030
TIME_FORMAT_FULL_1
15-01-2024 10:30:00
TIME_FORMAT_FULL_2
15/01/2024 10:30:00
TIME_FORMAT_24_FULL
2024-01-15 10:30:00
TIME_FORMAT_READABLE
15 January 2024 10:30 AM
TIME_FORMAT_READABLE_2
Jan 15, 2024 10:30 AM
TIME_FORMAT_SIMPLE
10:30:00
LogFileExtension
Value
Extension
LOG
.log
TXT
.txt
CSV
.csv
NONE
(no extension)
LogLevel
Value
Use for
INFO
General informational events
WARNING
Potentially harmful situations
ERROR
Error events that allow the app to continue
SEVERE
Critical failures
FormatType
Value
Entry format
FORMAT_CURLY
{tag} {message} {timestamp}
FORMAT_SQUARE
[tag] [message] [timestamp]
FORMAT_CSV
Comma-separated (or csvDelimiter) columns
FORMAT_CUSTOM
Uses customFormatOpen / customFormatClose as delimiters
ExportType(used in export calls, not initLogs)
Value
Exports logs from
TODAY
The current day
LAST_HOUR
The last 60 minutes
LAST_24_HOURS
The last 24 hours
WEEKS
The last 7 days
ALL
All retained log files
How to log data?
You have 2 choices for logging:
Hourly Logs
Hourly logs are automatically generated once this line is called. These logs are sorted and named according to current time (24h format) on device e.g. 0110202013.log
FlutterLogs.logThis(
tag: 'MyApp',
subTag: 'logData',
logMessage:
'This is a log message: ${DateTime.now().millisecondsSinceEpoch}',
level: LogLevel.INFO);
Or simply call this:
FlutterLogs.logInfo("TAG", "subTag", "My Log Message");
FlutterLogs.logWarn("TAG", "subTag", "My Log Message");
FlutterLogs.logError("TAG", "subTag", "My Log Message");
FlutterLogs.logErrorTrace("TAG", "subTag", "My Log Message", Error());
This will create a new file in storage directory according to time on device. For a single date, all logs will be present in a single directory.
Custom File Logs
If you want to log data into a specific file for some events, you can do this in 2 steps:
These logs will be kept in a seperate file.
Step 1:
[IMPORTANT] Define log file name in logs configuration, logger needs the name to find the file on storage, otherwise no data will be logged.
Here 3 files of logs are defined, logger will use these file name as keys to write data in them.
try {
var i = 100 ~/ 0;
print("$i");
} catch (e) {
FlutterLogs.logThis(
tag: 'MyApp',
subTag: 'Caught an exception.',
logMessage: 'Caught an exception!',
exception: e,
level: LogLevel.ERROR);
}
Printing error logs:
try {
var i = null;
print(i * 10);
} catch (e) {
FlutterLogs.logThis(
tag: 'MyApp',
subTag: 'Caught an error.',
logMessage: 'Caught an exception!',
error: e,
level: LogLevel.ERROR);
}
Backpressure Support
Backpressure helps manage high-volume logging scenarios by limiting queue size and setting quotas per log level to prevent memory issues and ensure critical logs are prioritized.
awaitFlutterLogs.initLogs(
// ... other configurations ...
backpressureConfig: BackpressureConfig(
queueCapacity: 500, // Max logs in queue before dropping
warnQueueCapacity: 400, // Warn when queue reaches this size
perLevelQuotas: {
LogLevel.INFO: 100, // Max 100 INFO logs per windowLogLevel.WARNING: 50, // Max 50 WARNING logs per windowLogLevel.ERROR: 200, // Prioritize error logsLogLevel.SEVERE: 200, // Prioritize severe logs
},
quotaWindowMillis: 60000, // 1 minute window for quotas
),
);
Redaction & Masking (PII Protection)
Automatically mask sensitive data like emails, phone numbers, credit cards, and custom patterns in your logs for privacy and security compliance.
Search through all log files for specific keywords and export or print only matching lines.
Export Filtered Logs
FlutterLogs.exportFilteredLogs(
keywords: ['ERROR', 'login', 'failed'],
filterType: FilterType.OR, // Match ANY keyword (use AND to match ALL)
exportType: ExportType.ALL,
ignoreCase: true,
);
Print Filtered Logs
FlutterLogs.printFilteredLogs(
keywords: ['network', 'timeout'],
filterType: FilterType.AND, // Match ALL keywords
exportType: ExportType.TODAY,
ignoreCase: true,
);
Filter Types
FilterType
Description
FilterType.OR
Match lines containing ANY of the keywords
FilterType.AND
Match lines containing ALL of the keywords
ELK Elastic Stack Schema Support
Send additional Meta info for better filtering at LogStash dashboard. With this setting, logs will be logged as JSON-delemited.