Housekeeping: Logged messages now follow a given standard#167
Housekeeping: Logged messages now follow a given standard#167
Conversation
|
I'm not sure if the panic hook is good practice, but I haven't found a better way to forward the panic messages to the logger |
There was a problem hiding this comment.
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
src/reddit_api.rs:233
- [nitpick] Consider aligning the logging level for 'Missing ratelimit' messages across the codebase. In src/reddit_api.rs the message uses warn! while in src/main.rs a similar situation uses error!; review and adjust the severity to ensure consistent behavior.
warn!("Missing ratelimit")
There was a problem hiding this comment.
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
src/main.rs:271
- If the intention is to clear the file contents before writing new comment IDs, consider using '.truncate(true)' to avoid leaving stale data from previous runs.
.truncate(false)
|
The first copilot comment was actually unexpectedly helpful |
src/calculation_results.rs
Outdated
| match self { | ||
| CalculationResult::Exact(n) => write!(f, "Exact({})", truncate(n)), | ||
| CalculationResult::Approximate(of, int) => { | ||
| write!(f, "Approximate({:?}, {})", of, truncate(int)) |
There was a problem hiding this comment.
That's going to be really long, a 3.4 would be displayed as OrdFloat { inner: 3.399999999999999911182158029987476766109466552734375000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 } (More than 25 digits every time). Would maybe make more sense to do, what we do for formatting them and .as_float().to_f64().
Otherwise, at least truncate it (though we really don't need to have it tell us it's an OrdFloat).
There was a problem hiding this comment.
That's a very good point, didn't think of long Floats
There was a problem hiding this comment.
Truncation now displays as following (3.4 on my machine is also a bit different):
INFO | factorion-bot | 2025-04-06T20:49:45Z | Comment -> RedditComment { id: "t1_mlramm9", calculation_list: [Calculation { value: 3.400000000000000000..., steps: [(1, 0)], result: Float(10.13610185115513210...) }], author: "tolik518", notify: None, subreddit: "test", status: Status { already_replied_or_rejected: false, not_replied: true, number_too_big_to_calculate: false, no_factorial: false, reply_would_be_too_long: false, factorials_found: true }, commands: Commands { shorten: false, steps: false, termial: false, no_note: false, post_only: false } }
|
Don't know if you want to do that in a separate pull, but I have some proposals for debug/trace logs:
In general, I would use |
|
All those logs would make sense. I'm not sure how I'd differentiate trace and debug tbh. Not sure if I'll implement the proposed logs in that pr, or create a separate one. I'll take a look at it in the evening. |
Aras14HD
left a comment
There was a problem hiding this comment.
Other than the one instance of code duplication, everything looks good now.
| fn truncate<T: fmt::Debug>(val: &T) -> String { | ||
| let s = format!("{:?}", val); | ||
| if s.len() > 25 { | ||
| format!("{}...", &s[..20]) | ||
| } else { | ||
| s | ||
| } | ||
| } |
There was a problem hiding this comment.
While this one duplication is not much of a problem, if it becomes more, you really should just move it outside. Would make it easier to for example change the length of the truncation.
There was a problem hiding this comment.
Yeah you're right, I was just struggling to find a fitting place for the function
Factorion will now write logs in a standardized format. This is part of the preparations for introducing the ELK stack (or some other centralized logging) to my server.
before
after