Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't suppress LibPQ's error output #283

Closed
nguiard opened this issue Sep 29, 2023 · 2 comments
Closed

Can't suppress LibPQ's error output #283

nguiard opened this issue Sep 29, 2023 · 2 comments

Comments

@nguiard
Copy link

nguiard commented Sep 29, 2023

Hi, thanks a lot for this library!

I have a bit of code that, by design, tries to connect to a non-existent database. I expect an error so I put it in a try/catch block, but libpq's red error message is still printed to screen. To be clear, the rest of the code works, it's just a bit annoying that users would see a red message that actually shouldn't be treated as an error.

Even with Suppressor.jl macros or setting throw_error=false, the message still gets through.
Any idea how I could disable that temporarily?

Minimal example:

using LibPQ

try
    c = LibPQ.Connection("dbname=x host=/notexists")
catch e
    # do nothing
end

output (in red):

[error | LibPQ]: connection to server on socket "/notexists/.s.PGSQL.5432" failed: No such file or directory
	Is the server running locally and accepting connections on that socket?
@iamed2
Copy link
Collaborator

iamed2 commented Sep 29, 2023

LibPQ.jl uses https://github.com/invenia/Memento.jl for logging (which I think we can remove at some point), so you can use functions from that package to suppress logs.

You can either temporarily set the log level for LibPQ.jl for your function:

setlevel!(getlogger("LibPQ"), "critical") do 
    mything()
end

set the log level globally for your application with a setlevel!(getlogger("LibPQ"), "critical"), or use Memento filters (I'd have to hunt through Memento for a good example of how to do that).

@iamed2 iamed2 closed this as completed Sep 29, 2023
@nguiard
Copy link
Author

nguiard commented Sep 29, 2023

Oh thanks a lot!

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

No branches or pull requests

2 participants