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

Non-error logs are printed to stderr #118

Open
ku1ik opened this issue Feb 3, 2022 · 4 comments
Open

Non-error logs are printed to stderr #118

ku1ik opened this issue Feb 3, 2022 · 4 comments

Comments

@ku1ik
Copy link

ku1ik commented Feb 3, 2022

As in title. This makes alerting configuration based on log severity problematic because everything seems to be an error. Most logging aggregation tools and platforms treat stderr output as level=error.

For example, "New tick of statistics from 10.9.1.100: 2497 ads blocked / 26870 total DNS queries" is not an error but it logged to stderr.

Steps for Reproduction

Run the exporter, redirect stderr to a file, observe all logs being saved there.

Expected behavior:

Informational logs are printed to stdout, and only errors are printed to stderr.

Actual behavior:

All logs, including informational, are printed to stderr.

Platforms:

Ubuntu 20.04, x86 64-bit

Versions:

0.1.1

@Galorhallen
Copy link
Contributor

This should be handled with #110, which also introduce log levels

@ku1ik
Copy link
Author

ku1ik commented Feb 10, 2022

Nice!

@wzzrd
Copy link

wzzrd commented Aug 21, 2024

@proggaras Did it though? Because I still get all logs through stderr even today. I was just browsing through my logs, an all logs generated by pihole exporter - even though they say level=info in the body - are still logged to stderr, not stdout.

Maybe I'm missing something though?

@wzzrd
Copy link

wzzrd commented Aug 21, 2024

~/tmp/2024-08-21
➜ ./pihole_exporter-darwin-amd64 > foo
INFO[0000] ------------------------------------
INFO[0000] -  PI-Hole exporter configuration  -
INFO[0000] ------------------------------------
INFO[0000] Go version: go1.20.1
INFO[0000] PIHoleProtocol : [http]
INFO[0000] PIHoleHostname : [127.0.0.1]
INFO[0000] PIHolePort : [80]
INFO[0000] Port : 9617
INFO[0000] Timeout : 5s
INFO[0000] ------------------------------------
INFO[0000] New Prometheus metric registered: domains_blocked
INFO[0000] New Prometheus metric registered: dns_queries_today
INFO[0000] New Prometheus metric registered: ads_blocked_today
INFO[0000] New Prometheus metric registered: ads_percentag_today
INFO[0000] New Prometheus metric registered: unique_domains
INFO[0000] New Prometheus metric registered: queries_forwarded
INFO[0000] New Prometheus metric registered: queries_cached
INFO[0000] New Prometheus metric registered: clients_ever_seen
INFO[0000] New Prometheus metric registered: unique_clients
INFO[0000] New Prometheus metric registered: dns_queries_all_types
INFO[0000] New Prometheus metric registered: reply
INFO[0000] New Prometheus metric registered: top_queries
INFO[0000] New Prometheus metric registered: top_ads
INFO[0000] New Prometheus metric registered: top_sources
INFO[0000] New Prometheus metric registered: forward_destinations
INFO[0000] New Prometheus metric registered: querytypes
INFO[0000] New Prometheus metric registered: status
INFO[0000] Creating client with config <Config@C000282058 PIHoleProtocol=http, PIHoleHostname=127.0.0.1, PIHolePort=80>
INFO[0000] Starting HTTP server
^C2024/08/21 10:41:05 pihole-exporter HTTP server stopped

~/tmp/2024-08-21
➜ cat foo

~/tmp/2024-08-21
➜ ./pihole_exporter-darwin-amd64 > foo 2>&1
 
~/tmp/2024-08-21
➜ head foo
time="2024-08-21T10:41:10+02:00" level=info msg=------------------------------------
time="2024-08-21T10:41:10+02:00" level=info msg="-  PI-Hole exporter configuration  -"
time="2024-08-21T10:41:10+02:00" level=info msg=------------------------------------
time="2024-08-21T10:41:10+02:00" level=info msg="Go version: go1.20.1"
time="2024-08-21T10:41:10+02:00" level=info msg="PIHoleProtocol : [http]"
time="2024-08-21T10:41:10+02:00" level=info msg="PIHoleHostname : [127.0.0.1]"
time="2024-08-21T10:41:10+02:00" level=info msg="PIHolePort : [80]"
time="2024-08-21T10:41:10+02:00" level=info msg="Port : 9617"
time="2024-08-21T10:41:10+02:00" level=info msg="Timeout : 5s"
time="2024-08-21T10:41:10+02:00" level=info msg=------------------------------------

As you see above, when I redirect output with > foo, the file "foo" remains empty, because stdout is not being used. Only when I redirect stderr to stdout the "foo" file is filled with messages.

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

3 participants