-
Hello everyone, I am using the Logger package for the logs in my mobile application (iOS & Android). I have implemented a LoggerHelper as it : import 'dart:async';
import 'package:logger/logger.dart';
import 'package:abc/main.dart';
class LoggerHelper {
final int maxFileSizeKB = 1024;
final int maxRotatedFilesCount = 5;
static Level _logLevel = Level.info;
Logger? _loggerInstance;
LoggerHelper() {
_loggerInstance = Logger(
printer: SimplePrinter(
printTime: true,
colors: false,
),
level: _logLevel,
output: MultiOutput([
AdvancedFileOutput(
path: logDir.path,
maxFileSizeKB: maxFileSizeKB,
maxRotatedFilesCount: maxRotatedFilesCount,
maxDelay: const Duration(seconds: 1),
),
ConsoleOutput(),
]),
);
}
Future<void> setLogLevel(Level level) async {
_logLevel = level;
}
Level getLogLevel() {
return _logLevel;
}
void trace(String message) {
_loggerInstance?.t(message);
}
void debug(String message) {
_loggerInstance?.d(message);
}
void info(String message) {
_loggerInstance?.i(message);
}
void warning(String message) {
_loggerInstance?.w(message);
}
void error(String message, [dynamic error]) {
_loggerInstance?.e(message, error: error, stackTrace: StackTrace.current);
}
} Then I start directly by calling this function in my main : Future<void> _initializeLogger() async {
WidgetsFlutterBinding.ensureInitialized();
final directory = await getApplicationDocumentsDirectory();
logDir = Directory('${directory.path}/logs');
if (!logDir.existsSync()) {
logDir.createSync(recursive: true);
}
final info = await PackageInfo.fromPlatform();
LoggerHelper().info('-- Booting Application -- ');
LoggerHelper().info('With Version: ${info.version} - ${info.buildNumber}');
} When i am running my app in simulators ( ios or android ), everything logs fine, and i can zip the file and export it and all the logs are written in the files. Do you know what i am doing wrong or if i am missing something ? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, it seems like you are missing a |
Beta Was this translation helpful? Give feedback.
Hi, it seems like you are missing a
LogFilter
: #43 (comment).