Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
04da9c73
Commit
04da9c73
authored
Jan 24, 2017
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create only one log roller per file across whole process (fixes #1363)
parent
16250da3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
6 deletions
+27
-6
caddyhttp/httpserver/roller.go
caddyhttp/httpserver/roller.go
+27
-6
No files found.
caddyhttp/httpserver/roller.go
View file @
04da9c73
...
@@ -2,6 +2,7 @@ package httpserver
...
@@ -2,6 +2,7 @@ package httpserver
import
(
import
(
"io"
"io"
"path/filepath"
"strconv"
"strconv"
"github.com/mholt/caddy"
"github.com/mholt/caddy"
...
@@ -19,14 +20,30 @@ type LogRoller struct {
...
@@ -19,14 +20,30 @@ type LogRoller struct {
}
}
// GetLogWriter returns an io.Writer that writes to a rolling logger.
// GetLogWriter returns an io.Writer that writes to a rolling logger.
// This should be called only from the main goroutine (like during
// server setup) because this method is not thread-safe; it is careful
// to create only one log writer per log file, even if the log file
// is shared by different sites or middlewares. This ensures that
// rolling is synchronized, since a process (or multiple processes)
// should not create more than one roller on the same file at the
// same time. See issue #1363.
func
(
l
LogRoller
)
GetLogWriter
()
io
.
Writer
{
func
(
l
LogRoller
)
GetLogWriter
()
io
.
Writer
{
return
&
lumberjack
.
Logger
{
absPath
,
err
:=
filepath
.
Abs
(
l
.
Filename
)
if
err
!=
nil
{
absPath
=
l
.
Filename
// oh well, hopefully they're consistent in how they specify the filename
}
lj
,
has
:=
lumberjacks
[
absPath
]
if
!
has
{
lj
=
&
lumberjack
.
Logger
{
Filename
:
l
.
Filename
,
Filename
:
l
.
Filename
,
MaxSize
:
l
.
MaxSize
,
MaxSize
:
l
.
MaxSize
,
MaxAge
:
l
.
MaxAge
,
MaxAge
:
l
.
MaxAge
,
MaxBackups
:
l
.
MaxBackups
,
MaxBackups
:
l
.
MaxBackups
,
LocalTime
:
l
.
LocalTime
,
LocalTime
:
l
.
LocalTime
,
}
}
lumberjacks
[
absPath
]
=
lj
}
return
lj
}
}
// ParseRoller parses roller contents out of c.
// ParseRoller parses roller contents out of c.
...
@@ -62,3 +79,7 @@ func ParseRoller(c *caddy.Controller) (*LogRoller, error) {
...
@@ -62,3 +79,7 @@ func ParseRoller(c *caddy.Controller) (*LogRoller, error) {
LocalTime
:
true
,
LocalTime
:
true
,
},
nil
},
nil
}
}
// lumberjacks maps log filenames to the logger
// that is being used to keep them rolled/maintained.
var
lumberjacks
=
make
(
map
[
string
]
*
lumberjack
.
Logger
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment