-
Notifications
You must be signed in to change notification settings - Fork 0
logging: allow to provide custom core factory func #152
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
base: main
Are you sure you want to change the base?
Conversation
It's kinda annoying that the tests spams the GHA logs with lots of log messages even though the tests aren't failing, see [^1] as an example. Since zap already provides a logger that logs to the testing.T instance, allow overriding the core factory to use that logger instead. This way, the logs are only visible when the test fails or when running the tests with the `-v` flag. [^1]: https://github.com/Icinga/icinga-notifications/actions/runs/17466069738/job/49602019404?pr=270
Oh, the tests on GitHub are of course run with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the tests on GitHub are of course run with the
-v
flag, this will only be relevant when running the tests locally.
I am unsure, but wouldn't just dropping -v
do the trick?
import ( | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
"os" | ||
"sync" | ||
"time" | ||
|
||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no reason to reorder the imports.
Most (or all?) Icinga Go code just uses one big import
block. While I personally dislike this pattern and would prefer grouped imports, it should at least be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not going over all the files now and group some random imports, I didn't even do this change by hand. Each time I edit a go file Goland do this automatically and I've to literally play cat and mouse with it, so that I can commit other relevant changes without this, but it's too annoying, so I gave up. And no, I'm not using any special IDE flags to enforce that grouping, like I said last time, it just seem to happen since the last upgrade.

As you can see, it just uses the simple goimports command without the Group packages from Go SDK option set, so 🤷♂️!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use goimports
but gofmt
. Maybe this is new?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm maybe, looking at the goimports command source code, its format-only
option says this:
if true, don't fix imports and only format. In this mode, goimports is effectively gofmt, with the addition that imports are grouped into sections.
The trick? Dropping the |
Ok, I'm noticing now that the existing incident tests do indeed use a zaptest logger, the problem was just due to a not yet pushed code of mine, which just uses a regular console logger. Nonetheless, it would be nice to have this helper function as it allows to construct a test |
It's kinda annoying that the tests spams the GHA logs with lots of log messages even though the tests aren't failing, see 1 as an example. Since zap already provides a logger that logs to the testing.T instance, allow overriding the core factory to use that logger instead. This way, the logs are only visible when the test fails or when running the tests with the
-v
flag.Tests
Footnotes
https://github.com/Icinga/icinga-notifications/actions/runs/17466069738/job/49602019404?pr=270 ↩