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
8 years ago
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
master
nxd-v0.11.0
nxd-v0.11.1
nxd-v0.11.5
nxd-v1.0.3
v1.0.0
v1.0.0-beta2
v1.0.0-beta1
v0.11.5
v0.11.4
v0.11.3
v0.11.2
v0.11.1
v0.11.1-4-g527de1864b6c33dac07c50694e07c50cb0abc3eb
v0.11.1-3-g5490ff205fed11f0972fde025934855d3a719d77
v0.11.0
v0.10.14
v0.10.13
v0.10.12
v0.10.11
v0.10.10
v0.10.9
v0.10.8
v0.10.7
v0.10.6
v0.10.5
v0.10.4
v0.10.3
v0.10.2
v0.10.1
v0.10.0
nxd-v1.0.3-1-g2c11cedc
nxd-v1.0.3-1-03fba31bf
nxd-v0.11.5-4-g9d3151db
nxd-v0.11.1-5-gdd393ce3a67e6a773be87185528a00f2e0a9eb26
nxd-v0.11.1-4-g527de1864b6c33dac07c50694e07c50cb0abc3eb
nxd-v0.11.1-3-g5490ff205fed11f0972fde025934855d3a719d77
nxd-v0.11.0-3-g12438f6cff8c15f307631151eb064cec579b7605
No related merge requests found
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
import
(
"io"
"path/filepath"
"strconv"
"github.com/mholt/caddy"
...
...
@@ -19,14 +20,30 @@ type LogRoller struct {
}
// 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
{
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
,
MaxSize
:
l
.
MaxSize
,
MaxAge
:
l
.
MaxAge
,
MaxBackups
:
l
.
MaxBackups
,
LocalTime
:
l
.
LocalTime
,
}
lumberjacks
[
absPath
]
=
lj
}
return
lj
}
// ParseRoller parses roller contents out of c.
...
...
@@ -62,3 +79,7 @@ func ParseRoller(c *caddy.Controller) (*LogRoller, error) {
LocalTime
:
true
,
},
nil
}
// lumberjacks maps log filenames to the logger
// that is being used to keep them rolled/maintained.
var
lumberjacks
=
make
(
map
[
string
]
*
lumberjack
.
Logger
)
This diff is collapsed.
Click to expand it.
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