Nate Lockwood
Nate Lockwood

Reputation: 3695

Dart How do I change the date format for the server logger

I implemented logging in my server side code today using defaults but the date part of the output string has minutes where the month should be. What is logged to the log file is:

2014.49.19 13:49:54.079 fireimager_server.WebSocketServer   [INFO]: [CLIENT] CAMERA CAMERAREADY
2014.49.19 13:49:54.081 fireimager_server.WebSocketServer   [INFO]: [CLIENT] RESET Finished
2014.50.19 13:50:05.447 fireimager_server.WebSocketServer   [INFO]: [CLIENT] DOOR OPEN

It appears that the date time format string (where ever it is) may look like:

"yyyy.mm.dd HH:mm:ss.SSS"

rather than

"yyyy.MM.dd HH:mm:ss.SSS"

Some code

import 'package:logging/logging.dart';
import 'package:logging_handlers/server_logging_handlers.dart';

// in main

Logger.root.onRecord.listen(new SyncFileLoggingHandler("/data/airbornescience/logs/server.log"));

// in Class MicroServer
static final _logger = new Logger("fireimager_server.MicroServer");

How can I supply my own date time to the logger or can this be fixed another way?

Upvotes: 1

Views: 360

Answers (1)

Claudio d'Angelis
Claudio d'Angelis

Reputation: 56

You can pass a StringTransformer to the SyncFileLoggingHandler constructor:

var trans = new StringTransformer(timestampFormat: "yyyy.MM.dd HH:mm:ss.SSS");

Logger.root.onRecord.listen(new SyncFileLoggingHandler(
'/data/airbornescience/logs/server.log', transformer: trans));

Edit: it appears to be a known bug of logging_handlers package; there is a pending pull request (#8) which will fix it.

Upvotes: 2

Related Questions