WVAviator / lorecraft

Generate and play AI adventure games. Built with Rust/Tauri and TypeScript/React/Tailwind.
1 stars 0 forks source link

Add fern and set up logging with log macros #1

Closed WVAviator closed 8 months ago

WVAviator commented 8 months ago

Add fern crate and create setup function to be called in main.rs before initializing the app.

Setup function should use multiple chained dispatchers (see https://docs.rs/fern/0.6.2/fern/struct.Dispatch.html) to log the following:

  1. All logs at INFO level and above should log to stdout
  2. Logs at debug level and above should also log to a file. For logs not associated with a game, they should log to the root data directory. Logs associated with a game should log to that games data directory. Should be able to use the record.target to determine any associated game

The log format should show the date and time for file logging only (consider using a crate like humantime as recommended by fern docs), the level and record prefixed for all other logs.

Consider setting up a yaml/JSON logger that, when invoked, saves these strings to their own files. Not sure how this could be configured or if it should just use the regular file management system. Maybe a pipe delineated record.target value (gameid|yaml) versus non delineated (gameid) could trigger this behavior.

Consider having the front end console logs routed to the back end as well, for convenience.

All existing logs should be revised to utilize the new logging setup.

WVAviator commented 8 months ago

Note that Tauri provides a path function for getting the recommend storage location for app logs. https://docs.rs/tauri/1.5.4/tauri/api/path/index.html

WVAviator commented 8 months ago

Logging to custom files based on the provided target is more challenging than originally anticipated. Basic logging is configured and working.