Skip to content

Silent logs#36

Merged
hannesm merged 2 commits intomirage:mainfrom
Julow:silent_logs
Apr 15, 2025
Merged

Silent logs#36
hannesm merged 2 commits intomirage:mainfrom
Julow:silent_logs

Conversation

@Julow
Copy link
Copy Markdown
Contributor

@Julow Julow commented Dec 18, 2024

I don't want to see what the ca-certs library does in my logs because it's generally too complex for me to understand and it generally just works.

The errors generated by fold_decode_pem_multiple are especially problematic because I cannot do anything about them and the authenticator works as intended anyway.

On NixOS, this message is repeated 175 times each time an authenticator is created:

my_app: [WARNING] Ignoring undecodable trust anchor: ignore non certificate.

@hannesm
Copy link
Copy Markdown
Member

hannesm commented Dec 18, 2024

Hmm, so... The default log level is "warn/error" - you shouldn't by default see the info/debug messages.

Another thing is in Logs you can adjust the log level of each specific log source -- so in your application if you desire to shut up the ca-certs log source, you could:

let silence_ca_certs () =
  match List.find_opt (fun src -> String.equal (List.Src.name src) "ca-certs") (Logs.Src.list ()) with
  | Some src -> Logs.Src.set_level src None
  | None -> assert false

But I agree that what you see is unpleasant - and we should demote some of these messages to debug. Also the "ignore non certificate" isn't very useful - maybe in the fold we should collect the errors and only print a single warning. The same strategy should be applied to the windows_trust_anchors -- and finally the error message (originating from x509) should be improved.

Would that work for you -- to have a single warning that 25000 things have been ignored (and on debug level, you get an explanation for each one)?

@Julow
Copy link
Copy Markdown
Contributor Author

Julow commented Dec 18, 2024

Thanks for the snippet, that solves my immediate problem :)
Note: This is undone by the next call to Logs.set_level.
To make this easier, shouldn't the log source be exposed in the library ? After all, logs are side effects that user might want to control.

The default log level is "warn/error" - you shouldn't by default see the info/debug messages.

I also don't want these to show up in the verbose output of my app. I changed everything to the debug level because at that level cohttp is also extremely verbose and I might still want to see what's wrong with certificates sometimes.

Would that work for you -- to have a single warning that 25000 things have been ignored (and on debug level, you get an explanation for each one)?

That's not satisfying to me as ca-certs just works (everytime for now) or errors-out. I don't want to see a permanent warning that I can't fix and also doesn't mean anything about the state of my app.

Perhaps that's only the case for the "ignore non certificate" warning, which could be completely silented while keeping the other warnings ?
Looking at x509's code, I'm thinking that this is just the result of the library not understanding some feature of certificates that is also not needed.

@hannesm
Copy link
Copy Markdown
Member

hannesm commented Apr 15, 2025

I pushed a commit to emit a single warning how many trust anchors have been ignored. I hope that is fine with you (i.e. you can live with this one log message), and plan to merge and release this.

Exposing the log source

I somehow agree. But am hesitant since this is not common in the Mirage ecosystem, and it would be great to have this uniform.

Looking at x509's code, I'm thinking that this is just the result of the library not understanding some feature of certificates that is also not needed.

My suspicion is your ca-certs file contains both pem-encoded certificates and their plain text dump -- where the latter is (rightfully) ignored.

Julow and others added 2 commits April 15, 2025 18:56
I don't want to see what the ca-certs library does in my logs because
it's generally too complex for me to understand and it generally just
works.

The errors generated by `fold_decode_pem_multiple` are especially
problematic because I cannot do anything about them and the
authenticator works as intended anyway.

On NixOS, this message is repeated 175 times each time an authenticator
is created:

    my_app: [WARNING] Ignoring undecodable trust anchor: ignore non certificate.
@hannesm hannesm merged commit eb8c2b1 into mirage:main Apr 15, 2025
6 of 7 checks passed
hannesm added a commit to hannesm/opam-repository that referenced this pull request Apr 15, 2025
CHANGES:

* Add OCAML_EXTRA_CA_CERTS env variable (mirage/ca-certs#30 @art-w)
* macOS: add additional keychain path `/Library/Keychains/System.keychain`
  (mirage/ca-certs#28 @ajbt200128)
* Demote log levels of trust anchor parsing failures (now on the debug level),
  log a single warning message how many failures occured (mirage/ca-certs#36 @Julow)
@hannesm
Copy link
Copy Markdown
Member

hannesm commented Apr 15, 2025

Thanks a lot for your report, PR, and your patience.

@Julow
Copy link
Copy Markdown
Contributor Author

Julow commented Apr 16, 2025

Thanks for looking at this :)

I've recently discovered how lwt_log helps setting libraries log levels with add_rule and I wonder if a similar mechanism could be interesting for the mirage ecosystem ?
This can possibly be implemented using a custom Logs reporter.

Basically it would allow to say things like "all logs from all mirage libraries are Info", "all logs from this rogue library are Error", "all logs from this part of my app are Debug". All while working with strings, which is interesting for tuning logs at runtime.

My suspicion is your ca-certs file contains both pem-encoded certificates and their plain text dump -- where the latter is (rightfully) ignored.

Perhaps we could avoid counting the rightfully ignored data when counting ignored data ? This could help remove the warning in some cases.

@hannesm
Copy link
Copy Markdown
Member

hannesm commented Apr 16, 2025

Dear @Julow, thanks for your reply.

add_rule

So, in MirageOS unikernels we have the -l parameter where you can specify the log level -- both the default, and also for a specific source, i.e. -l ca-certs:error,*:debug. This is not programmatically, and indeed modifies global mutable state.

Perhaps we could avoid counting the rightfully ignored data when counting ignored data?

Sure, that's a good idea. But I'm not sure how to classify the "rightfully ignored data"... We may have to dig a bit deeper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants