-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Fix traefik logs to behave like configured #2176
Fix traefik logs to behave like configured #2176
Conversation
Do we know why simply deferring isn't enough? Is this possibly related to a missed flush or a missing close? (I don't know if flushing stdout is even possible, just throwing around wild guesses here.) |
Yes, I checked that deferring is not enough. This is basically the first example I have written in the description above ( Frankly speaking, I also don't understand yet why this does not work. AFAICS the |
@timoreimann I was able to build a solution that captures all output by using After having implemented this, there was surprisingly still output written to the stdout. Namely this: Updating PR description right now. |
|
20e4471
to
ad9a21c
Compare
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.
😉
cmd/traefik/traefik.go
Outdated
// Try to fallback to traefik config file in case the file provider is enabled | ||
// but it has no file name configured. | ||
if fileProviderEnabled && len(globalConfiguration.File.Filename) == 0 && traefikConfigFileExists { | ||
globalConfiguration.File.Filename = traefikConfiguration.ConfigFile |
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.
Can you move this code in the run func, and use the "new" config file param
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 went one step further and pushed it down to SetEffectiveConfiguration
as it fits there best IMO.
|
||
if globalConfiguration.Debug { | ||
globalConfiguration.LogLevel = "DEBUG" | ||
} |
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.
this code should be in setEffectiveConfiguration ? WDYT
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 am not sure about that. The docs of SetEffectiveConfiguration
states:
SetEffectiveConfiguration adds missing configuration parameters derived from existing ones. It also takes care of maintaining backwards compatibility.
In my perception, this is actually not the case. LogLevel
is not a missing configuration parameter. It's meant to be this way.
Additionally SetEffectiveConfiguration
is called after configureLogging
, and that is for the good reason that the logging configuration should happen as first thing in order to achieve what this PR tries to achieve. Log all messages in the desired format and write them to a file if it is configured.
cmd/traefik/traefik.go
Outdated
logFile := globalConfiguration.TraefikLogsFile | ||
if len(logFile) > 0 { | ||
log.Warn("top-level traefiklogsfile has been deprecated -- please use traefiklog.filepath") | ||
} |
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.
this code should be in setEffectiveConfiguration and change the globalConfiguration.TraefikLog
value ? WDYT
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 don't think so, for the same reasons stated it in #2176 (comment).
@juliens I commented/addressed all your comments. PTAL again :-) |
|
Ups. Will fix Wednesday morning probably. Holiday :D |
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.
LGTM 👏 🗞️
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.
LGTM
cmd/traefik/traefik.go
Outdated
@@ -223,8 +211,23 @@ Complete documentation is available at https://traefik.io`, | |||
os.Exit(0) | |||
} | |||
|
|||
func run(globalConfiguration *configuration.GlobalConfiguration) { | |||
fmtlog.SetFlags(fmtlog.Lshortfile | fmtlog.LstdFlags) | |||
func run(traefikConfiguration *TraefikConfiguration) { |
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.
use high order function (and rename):
func runTraefikCmd(traefikConfiguration *TraefikConfiguration) func() error {
return func() error {
globalConfiguration := &traefikConfiguration.GlobalConfiguration
// ...
}
}
traefikConfiguration := NewTraefikConfiguration()
traefikPointersConfiguration := NewTraefikDefaultPointersConfiguration()
//traefik Command init
traefikCmd := &flaeg.Command{
Name: "traefik",
Description: `traefik is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease.
Complete documentation is available at https://traefik.io`,
Config: traefikConfiguration,
DefaultPointersConfig: traefikPointersConfiguration,
Run: runTraefikCmd(traefikConfiguration),
}
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.
Is this something I should address in a follow-up PR?
Also, can you explain a bit the benefit you see in this? We were discussing with @juliens that you want to keep run
function to not know anything about the traefikConfiguration
, because of a future feature you were working on. Is this still aligned with this effort?
The functions http.Serve and http.ServeTLS always return a non-nil error. In the "success" case, when the server is closed normally, they return ErrServerClosed. So we should only log when it is not that error.
416d7aa
to
9cea757
Compare
This PR accomplishes two things:
logrus.Exit()
and by closing the file in alogrus.RegisterExitHandler
.I also changed that errors from
http.Serve
andhttp.ServeTLS
are not logged anymore, in the case they are regularhttp.ErrServerClosed
errors, which is expected and the normal case. Those methods will never return a non-nil error.This fixes #2156.