MattJeanes / TeslaMateAgile

Integration to automatically fill in prices for charge data captured by TeslaMate for smart energy providers
MIT License
76 stars 9 forks source link

Make logging a little bit more useful #21

Closed jrothlis closed 3 years ago

jrothlis commented 3 years ago

Hi there, thanks for making such a nifty little utility. I recently switched from Octopus Agile to Octopus Go, so I've changed to "FixedPrice", but when I had a look at the logs (docker-compose logs) I noticed that the teslamateagile logs have no timestamps in them (compared to e.g. the teslamate logs). Would it be possible to add a timestamp (in a consistent format)?

A second request would be to expand "Updating prices" to something like "Updating prices: price is now 5p"?

Thanks!

MattJeanes commented 3 years ago

Hey there, for timestamps I recommend using the docker built in options to show timestamps: https://docs.docker.com/compose/reference/logs/

As for the updating prices, it's a bit of a misleading log really that's just what it says every time it checks to see if there is any new charges to calculate cost for

Hope this helps!

MattJeanes commented 3 years ago

Hopefully that's solved your issues. I will change the log message about updating prices to reduce confusion as I agree it is misleading.

jrothlis commented 3 years ago

Sorry for the late reply... This is what I mean about the logging, if I issue "docker-compose logs" I get the teslamate logs nicely time-stamped, but the teslamateagile logs are very sparse:

<snip>
teslamate_1       | 2021-06-27 16:52:52.541 [info] GET /public/build/moment~app.fd61e9de3c3d9b43f138.js
teslamate_1       | 2021-06-27 16:52:52.541 [info] Sent 404 in 244µs
teslamate_1       | 2021-06-27 16:52:52.542 [info] GET /public/build/unicons~app.fd61e9de3c3d9b43f138.js
teslamate_1       | 2021-06-27 16:52:52.543 [info] Sent 404 in 159µs
teslamateagile_1  | info: TeslaMateAgile.PriceHelper[0]
teslamateagile_1  |       Updating prices
teslamateagile_1  | info: TeslaMateAgile.PriceHelper[0]
teslamateagile_1  |       No new charging processes
<snip>
MattJeanes commented 3 years ago

If you add --timestamp onto the docker-compose logs you will get the timestamp info for TeslaMateAgile, but this will cause double timestamps for things like TeslaMate.

If you want the app to directly output timestamps in the same style as TeslaMate itself you can add the following environment variables:

- Logging__Console__FormatterName=simple
- "Logging__Console__FormatterOptions__TimestampFormat=yyyy-MM-dd hh:mm:ss.fff "

Note that quote marks around the second one are needed as there should be a space at the end of the timestamp format.

That will look like this:

matt@abyss:~$ sudo docker logs teslamateagile --since 1m -f
2021-07-04 03:01:00.871 info: TeslaMateAgile.PriceService[0]
      Price service is starting
2021-07-04 03:01:00.875 info: TeslaMateAgile.PriceService[0]
      Using energy provider FixedPrice
2021-07-04 03:01:00.876 info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
2021-07-04 03:01:00.878 info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
2021-07-04 03:01:00.878 info: Microsoft.Hosting.Lifetime[0]
      Content root path: /app/
2021-07-04 03:01:02.279 info: TeslaMateAgile.PriceHelper[0]
      No new charging processes
2021-07-04 03:01:02.282 info: TeslaMateAgile.PriceService[0]
      Waiting 300 seconds until next update

Check out this page for options on what formats you can use: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings

I have now also removed the Updating prices log message to reduce confusion, this will go out in the next release v1.7.0.

I've also added to the README about how to enable timestamps as above too so others can do the same if they wish.

Hopefully this is what you were looking for 😄

jrothlis commented 3 years ago

Thanks, perfect!!

jrothlis commented 3 years ago

Note that the formatting should be like this for 24h format (HH rather than hh):

- "Logging__Console__FormatterOptions__TimestampFormat=yyyy-MM-dd HH:mm:ss.fff "

MattJeanes commented 3 years ago

Good spot! I will update the readme accordingly, glad it's all working for you 🙂