-
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
Create log folder if not present #1507
Conversation
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.
Two more things:
- We are yet missing a test assertion. Could you add a check verifying that the file exists after we have created the logger?
- Please replace the hand-crafted determination of the platform-dependent temporary folder by a call to
os.TempDir
.
middlewares/logger.go
Outdated
|
||
err := os.MkdirAll(dir, 0755) | ||
if err != nil { | ||
log.Error("Error making directories ", err) |
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 we mention the log directory like
"Failed to create log path %s: %s", dir, err
middlewares/logger_test.go
Outdated
@@ -20,7 +20,7 @@ type logtestResponseWriter struct{} | |||
|
|||
var ( | |||
logger *Logger | |||
logfileName = "traefikTestLogger.log" | |||
logfileName = "/traefik/logger/test.log" |
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.
Could you rename this to logfileNameSuffix
since it will be concatenated with the actual temp directory.
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.
Could you please also remove the global variable logfilePath
? It suffices to live on the test function stack.
Thank you for your feedbacks @timoreimann |
Apparently, log files are now created at two locations. Is that necessary? Aren't those the same log files? |
I'm afraid not. One is traefik log file, the other is access log file. |
middlewares/logger_test.go
Outdated
logfilePath = filepath.Join("/tmp", logfileName) | ||
tmp, err := ioutil.TempDir("", "testlogger") | ||
if err != nil { | ||
t.Fatal("failed to create temp dir: ", err) |
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 we use Fatalf
and %s
just for consistency reasons?
middlewares/logger_test.go
Outdated
defer logger.Close() | ||
|
||
if _, err := os.Stat(logfilePath); err != nil { | ||
t.Fatalf("logger should create %q", logfilePath) |
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.
Any particular reason we're using %q
here as opposed to just %s
?
if err != nil { | ||
log.Errorf("Failed to create log path %s: %s", dir, err) | ||
} | ||
|
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.
The file seems completely untested, but making it properly testable is likely a bigger refactoring we want to source out to a different PR.
Could you verify manually that this part of the code change works as expected please?
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.
Sure.
middlewares/logger_test.go
Outdated
defer cleanup() | ||
defer logger.Close() | ||
|
||
if _, err := os.Stat(logfilePath); err != nil { |
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 think you need os.IsNotExist, don't you?
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.
Could you squash please?
6ff3b0f
to
67154a0
Compare
CI flaked out -- retriggered. |
@emilevauge @ldez looks simple enough to still get into 1.3, WDYT? |
@timoreimann why not, my biggest concern is that this PR #1485 is a big refactor of the logger and we will probably not be able to merge the current one once #1485 is merged. WDYT @tanyadegurechaff ? |
@emilevauge this change is rather smallish. My assumption is that it should be easy for #1485 to adjust / fix a smallish merge commit. @rjshep, any thoughts? |
@emilevauge put differently, I'd rather have the big change pay an integration effort for a small change than the other way around. Or is it that #1485 does things so fundamentally different as far as this PR is concerned that we will run into bigger problems I don't see right now? |
Due to SemaphoreCI, I close and reopen the PR. |
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.
Thanks @tanyadegurechaff !
LGTM
Description
Fixes #1217