SourceHorizon / logger

Small, easy to use and extensible logger which prints beautiful logs.
https://pub.dev/packages/logger
MIT License
197 stars 33 forks source link

FileOutput not working on Windows #68

Closed azlekov closed 4 months ago

azlekov commented 5 months ago

Hello, I'm trying to save log files on Windows. The files are created, but the logs are empty. On macOS the same code is working as expected.

Here is how I'm configuring the logger:

logger = Logger(
      printer: kDebugMode
          ? PrettyPrinter()
          : PrettyPrinter(
              colors: false, noBoxingByDefault: true, printEmojis: false),
      output: kDebugMode
          ? ConsoleOutput()
          : FileOutput(
              file: File(
              p.join(appLogsDir.path,
                  "app-${DateTime.now().toIso8601String().replaceAll(":", "-")}.log"),
            )));

Also I tried to "flush" the logs by calling logger.close() on app exit, again without any success.

Is there something wrong I'm doing?

Bungeefan commented 5 months ago

Hi, your snippet only logs to file if the Flutter app runs at least in profile or release mode, however, the default DevelopmentFilter only logs in debug mode. Therefore, your log file was probably empty while running in release mode.

I modified your snippet and either removed the kDebugMode check or set a filter that logs in release mode (e.g. ProductionFilter), and besides that, everything worked for me. Tested on Windows 11 23H2.