tobyweston / temperature-machine

Data logger for multiple DS18B20 temperature sensors on one or more machines
Apache License 2.0
67 stars 22 forks source link

Better error reporting #21

Closed tobyweston closed 6 years ago

tobyweston commented 6 years ago

Make the log viewable in the app and show dates / times.

Bit of a shame as I made an effort to display interesting startup output (below)

Starting temperature-machine (server mode)...
RRD initialising for 'study', 'bedroom1', 'bedroom2', 'bedroom3', 'outside', 'kitchen', 'lounge' (with up to 5 sensors each)...Ok
Starting Discovery Server, listening for 'study', 'bedroom1', 'bedroom2', 'bedroom3', 'outside', 'kitchen', 'lounge'...
Listening for broadcast messages...
Monitoring sensor file(s) on 'study' 
    /sys/bus/w1/devices/28-031591c760ff/w1_slave
Temperature spikes greater than +/-25% will not be recorded
HTTP Server started on http://127.0.1.1:11900
UnexpectedError(Failed to PUT temperature data to http://127.0.1.1:11900/temperature, response was 502 Bad Gateway: Error in RRD Bad sample time: 1507971519. Last update time was 1507971519, at least one second step is required)

Which would get muddled a little if I swap in an arbitrary logging framework:

2017-10-16 22:50:58:391 [main] INFO Starting temperature-machine (server mode)...
2017-10-16 22:50:58:427 [main] INFO RRD initialising for 'test', 'test2' (with up to 5 sensors each)...
2017-10-16 22:50:58:439 [main] INFO Ok
2017-10-16 22:51:09:128 [main] INFO Starting Discovery Server, listening for 'test', 'test2'...
2017-10-16 22:51:09:136 [temperature-machine-discovery-server-1] INFO Listening for broadcast messages...
2017-10-16 22:51:09:170 [main] INFO Monitoring sensor file(s) on 'MacBook-Pro' 
    /Users/toby/Workspace/github/temperature-machine/src/test/resources/more_examples/28-000005e2fdc2/w1_slave
    /Users/toby/Workspace/github/temperature-machine/src/test/resources/more_examples/28-000005e2fdc3/w1_slave

2017-10-16 22:51:09:317 [main] INFO Temperature spikes greater than +/-31% will not be recorded
2017-10-16 22:51:14:916 [main] INFO HTTP Server started on http://10.0.1.7:11900
2017-10-17 20:08:15:895 [temperature-machine-discovery-server-1] INFO Listening for broadcast messages...
2017-10-17 20:08:25:885 [temperature-machine-discovery-server-1] INFO Listening for broadcast messages...
2017-10-17 20:08:40:898 [temperature-machine-discovery-server-1] INFO Discovery server shutdown
tobyweston commented 6 years ago

NB. the current approach will take a standard text based log file and parse it on the fly to a List[LogMessage]. This has the problem where the LogParser can handle newlines and parse multi-line log messages into valid LogMessages, any client of the parser can't read a file a (conventional) line at a time.

So anything that goes Source.fromFile(...).getLines() can not feed the LogParser.

Alternatives might be to write the log file as JSON in the first place (which I didn't do first time round as I wanted a super-lightweight logging framework) or use a custom line ending delimiter in the log file (\u0000 springs to mind).

So instead of:

Source.fromFile(source).getLines()

You'd use a Scanner:

new Scanner(new File(source)).useDelimiter("\u0000").asScala
tobyweston commented 6 years ago

Still to do: