Logging #26

Open
leon wants to merge 33 commits from Logging into main
Owner

An initial implementation of logging (and also config) crates. Desperately needs some field-testing, further feedback and implementation of real LogMessageType-Variants.

It should be mainly used with the log!(LogMessage) macro.

Closes #15

An initial implementation of logging (and also config) crates. Desperately needs some field-testing, further feedback and implementation of real LogMessageType-Variants. It should be mainly used with the log!(LogMessage) macro. Closes #15
leon self-assigned this 2024-02-15 03:04:19 +01:00
leon added 18 commits 2024-02-15 03:04:19 +01:00
preliminary logging module
Some checks failed
continuous-integration/drone/push Build is failing
d330a48c55
Merge branch 'main' into Logging
Some checks failed
continuous-integration/drone/push Build is failing
c6b5dc7878
Reviewed-on: #18
rustfmt
Some checks failed
continuous-integration/drone/push Build is failing
f3b061a637
macros batman commit
Some checks failed
continuous-integration/drone/push Build is failing
a54a226cef
Merge branch 'main' into Logging
Some checks failed
continuous-integration/drone/push Build is failing
ad5b073338
i want auto-rustfmt
fixed doc example
All checks were successful
continuous-integration/drone/push Build is passing
d8b7616c43
rustfmt
All checks were successful
continuous-integration/drone/push Build is passing
ef9c2d4fd9
debugging and some unit tests
All checks were successful
continuous-integration/drone/push Build is passing
2580886d04
rustfmt
All checks were successful
continuous-integration/drone/push Build is passing
9110c16256
replaced from_str_radix with parse
All checks were successful
continuous-integration/drone/push Build is passing
eed7053b6d
Merge branch 'main' into Logging
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
49ce51295c
leon requested review from WANessa 2024-02-15 03:04:32 +01:00
leon added 1 commit 2024-02-15 15:03:29 +01:00
Merge branch 'main' into Logging
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing
2a2a2fd805
hendrik requested changes 2024-02-15 17:45:57 +01:00
hendrik left a comment
Owner

I suggest some stability changes:

LogVerbosity doesn't specify values, but logging/src/lib.rs:75 assumes order
-> Accidental reordering of the enum would lead to errors

config/src/lib.rs:67 declares setter for read-only struct
config/src/lib.rs:78 declares setter for read-only struct
config/src/lib.rs:89 declares setter for read-only struct
logging/src/test.rs:44 declares mutable variable with type intended as read-only
logging/src/test.rs:45 modifies variable intended to be read-only
-> Maybe just remove the setters and use an initializer to ensure immutability

logging/src/lib.rs:102 will panic if any code requests write-lock on config::CONFIG and then panics. Consider using Arc to ensure immutability and accessibility to the configuration from any thread at any time

logging/src/lib.rs:46 and logging/src/lib.rs:48 will panic if an IO error occurs. Maybe consider to not panic and print another error to the console, informing about the writing problems, rather than crashing the program as logging is not a crucial feature for the program's functioning

I suggest some stability changes: LogVerbosity doesn't specify values, but logging/src/lib.rs:75 assumes order -> Accidental reordering of the enum would lead to errors config/src/lib.rs:67 declares setter for read-only struct config/src/lib.rs:78 declares setter for read-only struct config/src/lib.rs:89 declares setter for read-only struct logging/src/test.rs:44 declares mutable variable with type intended as read-only logging/src/test.rs:45 modifies variable intended to be read-only -> Maybe just remove the setters and use an initializer to ensure immutability logging/src/lib.rs:102 will panic if any code requests write-lock on config::CONFIG and then panics. Consider using Arc<Config> to ensure immutability and accessibility to the configuration from any thread at any time logging/src/lib.rs:46 and logging/src/lib.rs:48 will panic if an IO error occurs. Maybe consider to not panic and print another error to the console, informing about the writing problems, rather than crashing the program as logging is not a crucial feature for the program's functioning
Author
Owner

I suggest some stability changes:

LogVerbosity doesn't specify values, but logging/src/lib.rs:75 assumes order
-> Accidental reordering of the enum would lead to errors

config/src/lib.rs:67 declares setter for read-only struct
config/src/lib.rs:78 declares setter for read-only struct
config/src/lib.rs:89 declares setter for read-only struct
logging/src/test.rs:44 declares mutable variable with type intended as read-only
logging/src/test.rs:45 modifies variable intended to be read-only
-> Maybe just remove the setters and use an initializer to ensure immutability

logging/src/lib.rs:102 will panic if any code requests write-lock on config::CONFIG and then panics. Consider using Arc to ensure immutability and accessibility to the configuration from any thread at any time

logging/src/lib.rs:46 and logging/src/lib.rs:48 will panic if an IO error occurs. Maybe consider to not panic and print another error to the console, informing about the writing problems, rather than crashing the program as logging is not a crucial feature for the program's functioning

I am splitting this into multiple reviews at the specific sections of code. I will @ you, so you know where to find it.

> I suggest some stability changes: > > LogVerbosity doesn't specify values, but logging/src/lib.rs:75 assumes order > -> Accidental reordering of the enum would lead to errors > > config/src/lib.rs:67 declares setter for read-only struct > config/src/lib.rs:78 declares setter for read-only struct > config/src/lib.rs:89 declares setter for read-only struct > logging/src/test.rs:44 declares mutable variable with type intended as read-only > logging/src/test.rs:45 modifies variable intended to be read-only > -> Maybe just remove the setters and use an initializer to ensure immutability > > logging/src/lib.rs:102 will panic if any code requests write-lock on config::CONFIG and then panics. Consider using Arc<Config> to ensure immutability and accessibility to the configuration from any thread at any time > > logging/src/lib.rs:46 and logging/src/lib.rs:48 will panic if an IO error occurs. Maybe consider to not panic and print another error to the console, informing about the writing problems, rather than crashing the program as logging is not a crucial feature for the program's functioning I am splitting this into multiple reviews at the specific sections of code. I will @ you, so you know where to find it.
leon reviewed 2024-02-15 18:34:43 +01:00
@ -0,0 +20,4 @@
#[derive(Clone, PartialEq, Eq, Getters, Setters, Debug)]
#[getset(get = "pub", set = "pub")]
#[allow(clippy::struct_excessive_bools)] // False positive, since this is a config struct.
pub struct Config {
Author
Owner

-> Maybe just remove the setters and use an initializer to ensure immutability

I considered this.
I just thought that setters are more convenient than using mem::swap or *config = Config::new(...). I also was not sure, if the config is truly read-only since we never specified if hot-reloading the config is a desired feature. Depending on how the CLI is implemented, hot-applying config-changes might also be a necessity to disable stdout logging, which would pollute the CLIs visuals.

@hendrik

> -> Maybe just remove the setters and use an initializer to ensure immutability I considered this. I just thought that setters are more convenient than using `mem::swap` or `*config = Config::new(...)`. I also was not sure, if the config is truly read-only since we never specified if hot-reloading the config is a desired feature. Depending on how the CLI is implemented, hot-applying config-changes might also be a necessity to disable stdout logging, which would pollute the CLIs visuals. @hendrik

I assumed the config would be read only, because some attribute changes after initialization could easily cause unexpected problems. For example, changing the database server at runtime is not something the current code is designed for, nor would it be a sensible feature to implement. If the log-settings should be mutable after the initialization phase, we should add a mutable reference to some "LogPreferences" structure to our Config instead of generally supporting hot-reload for the whole Config

@leon

I assumed the config would be read only, because some attribute changes after initialization could easily cause unexpected problems. For example, changing the database server at runtime is not something the current code is designed for, nor would it be a sensible feature to implement. If the log-settings should be mutable after the initialization phase, we should add a mutable reference to some "LogPreferences" structure to our Config instead of generally supporting hot-reload for the whole Config @leon
Author
Owner

Seems sensible. It is also probably a good idea to split the config struct into multiple parts.

Seems sensible. It is also probably a good idea to split the config struct into multiple parts.
Author
Owner
See a787dd93e5
@ -0,0 +135,4 @@
pub static CONFIG: RwLock<Config> = RwLock::new(DEFAULTS);
/**
* Each level includes the previous ones.
Author
Owner

LogVerbosity doesn't specify values, but logging/src/lib.rs:75 assumes order
-> Accidental reordering of the enum would lead to errors

It is mentioned here, that each level includes the previous ones, but including explicit ordinals is still a good idea.

> LogVerbosity doesn't specify values, but logging/src/lib.rs:75 assumes order > -> Accidental reordering of the enum would lead to errors It is mentioned here, that each level includes the previous ones, but including explicit ordinals is still a good idea.
Author
Owner
@hendrik
Author
Owner
See 6e73c2a7b7
hendrik marked this conversation as resolved
@ -0,0 +45,4 @@
.open(path)
.unwrap_or_else(|_| panic!("Could not open log file: {path:#?}"));
writeln!(file, "{log_line}")
.unwrap_or_else(|_| panic!("Could not write log to file: {path:#?}"));
Author
Owner

logging/src/lib.rs:46 and logging/src/lib.rs:48 will panic if an IO error occurs. Maybe consider to not panic and print another error to the console, informing about the writing problems, rather than crashing the program as logging is not a crucial feature for the program's functioning

While logging is not a dependency of the program's main function, it is a crucial part of administrating it. If the program cannot log to stdout because the feature was disabled by the admin or due to some problem, it could lead to an edge case-where the program has no logging and cannot inform the sysadmin about errors.

Although I see how panicking is not the best solution. A controlled shutdown is preferable and a config Option allowing the sysadmin to set a limit on how many log-messages may be dropped within x time, without the service shutting down.

@hendrik

> logging/src/lib.rs:46 and logging/src/lib.rs:48 will panic if an IO error occurs. Maybe consider to not panic and print another error to the console, informing about the writing problems, rather than crashing the program as logging is not a crucial feature for the program's functioning While logging is not a dependency of the program's main function, it is a crucial part of administrating it. If the program cannot log to stdout because the feature was disabled by the admin or due to some problem, it could lead to an edge case-where the program has no logging and cannot inform the sysadmin about errors. Although I see how panicking is not *the best* solution. A controlled shutdown is preferable and a config Option allowing the sysadmin to set a limit on how many log-messages may be dropped within x time, without the service shutting down. @hendrik

If the stdout was disabled, panicking wouldn't tell the admin about the error either. The whole program shutting down is not a good indicator for a failure, if not shutting down is a safe alternative. The program could also notify the admin via CLI, Internet, Email or many other ways that something went wrong while still keeping up its full functionality (as from the perspective of the user).

If the stdout was disabled, panicking wouldn't tell the admin about the error either. The whole program shutting down is not a good indicator for a failure, if not shutting down is a safe alternative. The program could also notify the admin via CLI, Internet, Email or many other ways that something went wrong while still keeping up its full functionality (as from the perspective of the user).
Author
Owner

The error in this case is the inability to report about warnings. This edge-case happens, when there is absolutely no way of informing the sysadmin of other errors, including CLI and E-Mail, etc.
Let's assume the program detects something which could to serious data-loss in the future. The program should warn the sysadmin about it, but not yet shut down, unless the error is possibly imminent. But if all configured ways of logging and communicating with the sysadmin fail, the service should try to shut down to prevent data loss or other unintended behavior.

I would suggest the following:

  • Introduce a serious-warning verbosity between error and warning for soon-to-be errors
  • implementing more log channels, such as E-Mail
  • implementing some sort of unwind&shutdown macro/function as a better alternative to panic!(), which would generally be useful
  • introduce a config-attribute, which determines if the service may be shut down due to errors in logging:
    • What verbosity must the log at least have?
    • How many log failures may happen?
    • In what amount of time?

But until then, I will remove the panic and spit something into stderr, ignoring the stderr setting.

The error in this case is the inability to report about warnings. This edge-case happens, when there is absolutely no way of informing the sysadmin of other errors, including CLI and E-Mail, etc. Let's assume the program detects something which could to serious data-loss in the future. The program should warn the sysadmin about it, but not yet shut down, unless the error is possibly imminent. But if all configured ways of logging and communicating with the sysadmin fail, the service should try to shut down to prevent data loss or other unintended behavior. I would suggest the following: - Introduce a serious-warning verbosity between error and warning for soon-to-be errors - implementing more log channels, such as E-Mail - implementing some sort of unwind&shutdown macro/function as a better alternative to panic!(), which would generally be useful - introduce a config-attribute, which determines if the service may be shut down due to errors in logging: - What verbosity must the log at least have? - How many log failures may happen? - In what amount of time? But until then, I will remove the panic and spit something into stderr, ignoring the stderr setting.
Author
Owner
See e4baaa5f45
@ -0,0 +99,4 @@
($msg:expr) => {
let conf = config::CONFIG
.read()
.unwrap_or_else(|_| panic!("Failed aqcuire read lock on config!"));
Author
Owner

logging/src/lib.rs:102 will panic if any code requests write-lock on config::CONFIG and then panics. Consider using Arc to ensure immutability and accessibility to the configuration from any thread at any time

Fair, although getting a mut ref on an Arc would require some while-looping everytime.

The same question about read-only config applies here:
https://git.libre.moe/KomuSolutions/WANessa/pulls/26/files#issuecomment-1519

When this function is stable, it might be used to clear the poison:
https://doc.rust-lang.org/std/sync/struct.RwLock.html#method.clear_poison

> logging/src/lib.rs:102 will panic if any code requests write-lock on config::CONFIG and then panics. Consider using Arc to ensure immutability and accessibility to the configuration from any thread at any time Fair, although getting a mut ref on an Arc would require some while-looping everytime. The same question about read-only config applies here: https://git.libre.moe/KomuSolutions/WANessa/pulls/26/files#issuecomment-1519 When this function is stable, it might be used to clear the poison: https://doc.rust-lang.org/std/sync/struct.RwLock.html#method.clear_poison
Author
Owner
@hendrik

Assuming the config is read-only, we could also use an Arc without while-looping everytime by using the Arc::clone() function. Also using Arcs would defeat the whole problem of poisoning due to no code being able to request a write-lock.

@leon

Assuming the config is read-only, we could also use an Arc without while-looping everytime by using the Arc::clone() function. Also using Arcs would defeat the whole problem of poisoning due to no code being able to request a write-lock. @leon
Author
Owner

While not a read lock, the Arc Type has this, which seems to be at odds with the whole immutability thing.
https://doc.rust-lang.org/std/sync/struct.Arc.html#method.get_mut
The docs don't seem to define what happens after you get the &mut and then panic before dropping the reference, which seems sketchy to me

To replace the compile-time default config with the runtime sysadmin config, we need to get a *mut reference for mem::swap to work. Otherwise, we can only have the default values, which defeats the point of a config.

While not a read lock, the Arc Type has this, which seems to be at odds with the whole immutability thing. https://doc.rust-lang.org/std/sync/struct.Arc.html#method.get_mut The docs don't seem to define what happens after you get the &mut and then panic before dropping the reference, which seems sketchy to me To replace the compile-time default config with the runtime sysadmin config, we need to get a *mut reference for [`mem::swap`](https://doc.rust-lang.org/std/mem/fn.swap.html) to work. Otherwise, we can only have the default values, which defeats the point of a config.
Author
Owner

Or alternatively, we could use this crate I once used in a test:
https://docs.rs/once_cell/latest/once_cell/sync/struct.Lazy.html

It would also make DEFAULT more sensible, since it can now use strings and other types of variable length.

Or alternatively, we could use this crate I once used in a test: https://docs.rs/once_cell/latest/once_cell/sync/struct.Lazy.html It would also make DEFAULT more sensible, since it can now use strings and other types of variable length.
Author
Owner

See a787dd93e5

TODO: Poison checking.

See a787dd93e5 TODO: Poison checking.
leon added 1 commit 2024-02-15 18:41:51 +01:00
added explicit ordinals; See #26
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
6e73c2a7b7
leon added 1 commit 2024-02-15 19:06:46 +01:00
expanded macro to optionally accept &Config
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing
a36a8a8b76
This is necessary, in case there is a write lock in the current scope,
which would prevent the log command from exiting
wanessa added 1 commit 2024-02-15 19:07:43 +01:00
rustfmt
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
9e378c7820
leon added 4 commits 2024-02-15 21:55:24 +01:00
this was done to have more fine-grain control over mutability over the different configs and settings of WANessa
Merge branch 'Logging' of git.libre.moe:KomuSolutions/WANessa into Logging
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing
502d3a7b2d
wanessa added 1 commit 2024-02-15 21:56:21 +01:00
rustfmt
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
cbfa4cbfdf
leon added 2 commits 2024-02-15 22:41:31 +01:00
replaced log_message with new log!
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
dd5bfff7d2
leon added 2 commits 2024-05-06 21:09:47 +02:00
todo: trait
Some checks reported errors
continuous-integration/drone/pr Build encountered an error
continuous-integration/drone/push Build is passing
beb337cefd
leon requested review from hendrik 2024-05-06 21:10:57 +02:00
leon changed title from WIP: Logging to Logging 2024-05-07 01:20:56 +02:00
Author
Owner

Drone CI seems to have some issues; either waiting for them to be resolved or the switch to gitea actions

Drone CI seems to have some issues; either waiting for them to be resolved or the switch to [gitea actions](https://git.libre.moe/KomuSolutions/WANessa/issues/28)
Owner

wdym with issues?

wdym with issues?
Author
Owner

wdym with issues?

Just take a look at them:
https://drone.libre.moe/KomuSolutions/WANessa/393

> wdym with issues? Just take a look at them: https://drone.libre.moe/KomuSolutions/WANessa/393
Owner

spannend, das könnte maybe an meine nginx config liegen, ich schau mir das mal an

spannend, das könnte maybe an meine nginx config liegen, ich schau mir das mal an
lukas self-assigned this 2024-05-09 19:30:23 +02:00
Owner

Der drone runner wollte anscheinend ~10MB an logs senden, das wollte sich mein nginx nicht gefallen lassen. Was generiert denn so imens viele logs, oder sind da auch build artefacts mit dabei?

Der drone runner wollte anscheinend ~10MB an logs senden, das wollte sich mein nginx nicht gefallen lassen. Was generiert denn so imens viele logs, oder sind da auch build artefacts mit dabei?
wanessa added 1 commit 2024-05-09 19:48:55 +02:00
rustfmt
Some checks reported errors
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build encountered an error
c2bade653a
Owner

naja, also mit erhöten nginx limits läuft jetzt drone in ein ram limit :)

naja, also mit erhöten nginx limits läuft jetzt drone in ein ram limit :)
Owner
![image](/attachments/a5b0df70-eb05-4717-b622-f9fd590ef232) found the problem https://drone.libre.moe/KomuSolutions/WANessa/397/1/3
181 KiB
Owner

Ich aktiviere mal wieder die Begrenzung für die HTTP Uploads, um die db nicht vollzuspammen. Das Problem scheint schließlich die CI zu sein.

Ich aktiviere mal wieder die Begrenzung für die HTTP Uploads, um die db nicht vollzuspammen. Das Problem scheint schließlich die CI zu sein.
Author
Owner

image
found the problem https://drone.libre.moe/KomuSolutions/WANessa/397/1/3

Lmao, but why didn't this appear in earlier commits?

> ![image](/attachments/a5b0df70-eb05-4717-b622-f9fd590ef232) > found the problem https://drone.libre.moe/KomuSolutions/WANessa/397/1/3 Lmao, but why didn't this appear in earlier commits?
Owner

idk, kenne mich nicht gut mit der pipeline aus, aber logs sollten eher unter 1MB sein :)
das wäre nett

idk, kenne mich nicht gut mit der pipeline aus, aber logs sollten eher unter 1MB sein :) das wäre nett
leon added 1 commit 2024-05-09 20:22:31 +02:00
hide test output to fix drone ci
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
16a30028f7
This repo is archived. You cannot comment on pull requests.
No reviewers
No Milestone
No project
No Assignees
4 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: KomuSolutions/WANessa#26
No description provided.