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
930ca1cc
Commit
930ca1cc
authored
Jan 28, 2019
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
main,log,errors: Option to disable log rotation ("rolling")
For log and errors directive, as well as process log.
parent
23627bbf
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
19 deletions
+44
-19
caddy/caddymain/run.go
caddy/caddymain/run.go
+24
-6
caddyhttp/httpserver/logger.go
caddyhttp/httpserver/logger.go
+2
-2
caddyhttp/httpserver/roller.go
caddyhttp/httpserver/roller.go
+16
-9
vendor/gopkg.in/natefinch/lumberjack.v2/lumberjack.go
vendor/gopkg.in/natefinch/lumberjack.v2/lumberjack.go
+1
-1
vendor/manifest
vendor/manifest
+1
-1
No files found.
caddy/caddymain/run.go
View file @
930ca1cc
...
@@ -56,6 +56,8 @@ func init() {
...
@@ -56,6 +56,8 @@ func init() {
flag
.
StringVar
(
&
certmagic
.
Email
,
"email"
,
""
,
"Default ACME CA account email address"
)
flag
.
StringVar
(
&
certmagic
.
Email
,
"email"
,
""
,
"Default ACME CA account email address"
)
flag
.
DurationVar
(
&
certmagic
.
HTTPTimeout
,
"catimeout"
,
certmagic
.
HTTPTimeout
,
"Default ACME CA HTTP timeout"
)
flag
.
DurationVar
(
&
certmagic
.
HTTPTimeout
,
"catimeout"
,
certmagic
.
HTTPTimeout
,
"Default ACME CA HTTP timeout"
)
flag
.
StringVar
(
&
logfile
,
"log"
,
""
,
"Process log file"
)
flag
.
StringVar
(
&
logfile
,
"log"
,
""
,
"Process log file"
)
flag
.
IntVar
(
&
logRollMB
,
"log-roll-mb"
,
100
,
"Roll process log when it reaches this many megabytes (0 to disable rolling)"
)
flag
.
BoolVar
(
&
logRollCompress
,
"log-roll-compress"
,
true
,
"Gzip-compress rolled process log files"
)
flag
.
StringVar
(
&
caddy
.
PidFile
,
"pidfile"
,
""
,
"Path to write pid file"
)
flag
.
StringVar
(
&
caddy
.
PidFile
,
"pidfile"
,
""
,
"Path to write pid file"
)
flag
.
BoolVar
(
&
caddy
.
Quiet
,
"quiet"
,
false
,
"Quiet mode (no initialization output)"
)
flag
.
BoolVar
(
&
caddy
.
Quiet
,
"quiet"
,
false
,
"Quiet mode (no initialization output)"
)
flag
.
StringVar
(
&
revoke
,
"revoke"
,
""
,
"Hostname for which to revoke the certificate"
)
flag
.
StringVar
(
&
revoke
,
"revoke"
,
""
,
"Hostname for which to revoke the certificate"
)
...
@@ -84,12 +86,26 @@ func Run() {
...
@@ -84,12 +86,26 @@ func Run() {
case
""
:
case
""
:
log
.
SetOutput
(
ioutil
.
Discard
)
log
.
SetOutput
(
ioutil
.
Discard
)
default
:
default
:
if
logRollMB
>
0
{
log
.
SetOutput
(
&
lumberjack
.
Logger
{
log
.
SetOutput
(
&
lumberjack
.
Logger
{
Filename
:
logfile
,
Filename
:
logfile
,
MaxSize
:
100
,
MaxSize
:
logRollMB
,
MaxAge
:
14
,
MaxAge
:
14
,
MaxBackups
:
10
,
MaxBackups
:
10
,
Compress
:
logRollCompress
,
})
})
}
else
{
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
logfile
),
0755
)
if
err
!=
nil
{
mustLogFatalf
(
"%v"
,
err
)
}
f
,
err
:=
os
.
OpenFile
(
logfile
,
os
.
O_APPEND
|
os
.
O_CREATE
|
os
.
O_WRONLY
,
0644
)
if
err
!=
nil
{
mustLogFatalf
(
"%v"
,
err
)
}
// don't close file; log should be writeable for duration of process
log
.
SetOutput
(
f
)
}
}
}
//Load all additional envs as soon as possible
//Load all additional envs as soon as possible
...
@@ -501,6 +517,8 @@ var (
...
@@ -501,6 +517,8 @@ var (
cpu
string
cpu
string
envFile
string
envFile
string
logfile
string
logfile
string
logRollMB
int
logRollCompress
bool
revoke
string
revoke
string
version
bool
version
bool
plugins
bool
plugins
bool
...
...
caddyhttp/httpserver/logger.go
View file @
930ca1cc
...
@@ -23,7 +23,7 @@ import (
...
@@ -23,7 +23,7 @@ import (
"strings"
"strings"
"sync"
"sync"
"github.com/hashicorp/go-syslog"
gsyslog
"github.com/hashicorp/go-syslog"
"github.com/mholt/caddy"
"github.com/mholt/caddy"
)
)
...
@@ -162,7 +162,7 @@ selectwriter:
...
@@ -162,7 +162,7 @@ selectwriter:
return
err
return
err
}
}
if
l
.
Roller
!=
nil
{
if
l
.
Roller
!=
nil
&&
!
l
.
Roller
.
Disabled
{
file
.
Close
()
file
.
Close
()
l
.
Roller
.
Filename
=
l
.
Output
l
.
Roller
.
Filename
=
l
.
Output
l
.
writer
=
l
.
Roller
.
GetLogWriter
()
l
.
writer
=
l
.
Roller
.
GetLogWriter
()
...
...
caddyhttp/httpserver/roller.go
View file @
930ca1cc
...
@@ -20,11 +20,12 @@ import (
...
@@ -20,11 +20,12 @@ import (
"path/filepath"
"path/filepath"
"strconv"
"strconv"
"gopkg.in/natefinch/lumberjack.v2"
lumberjack
"gopkg.in/natefinch/lumberjack.v2"
)
)
// LogRoller implements a type that provides a rolling logger.
// LogRoller implements a type that provides a rolling logger.
type
LogRoller
struct
{
type
LogRoller
struct
{
Disabled
bool
Filename
string
Filename
string
MaxSize
int
MaxSize
int
MaxAge
int
MaxAge
int
...
@@ -66,10 +67,11 @@ func IsLogRollerSubdirective(subdir string) bool {
...
@@ -66,10 +67,11 @@ func IsLogRollerSubdirective(subdir string) bool {
return
subdir
==
directiveRotateSize
||
return
subdir
==
directiveRotateSize
||
subdir
==
directiveRotateAge
||
subdir
==
directiveRotateAge
||
subdir
==
directiveRotateKeep
||
subdir
==
directiveRotateKeep
||
subdir
==
directiveRotateCompress
subdir
==
directiveRotateCompress
||
subdir
==
directiveRotateDisable
}
}
var
invalidRollerParameterEr
r
=
errors
.
New
(
"invalid roller parameter"
)
var
errInvalidRollParamete
r
=
errors
.
New
(
"invalid roller parameter"
)
// ParseRoller parses roller contents out of c.
// ParseRoller parses roller contents out of c.
func
ParseRoller
(
l
*
LogRoller
,
what
string
,
where
...
string
)
error
{
func
ParseRoller
(
l
*
LogRoller
,
what
string
,
where
...
string
)
error
{
...
@@ -79,16 +81,16 @@ func ParseRoller(l *LogRoller, what string, where ...string) error {
...
@@ -79,16 +81,16 @@ func ParseRoller(l *LogRoller, what string, where ...string) error {
// rotate_compress doesn't accept any parameters.
// rotate_compress doesn't accept any parameters.
// others only accept one parameter
// others only accept one parameter
if
(
what
==
directiveRotateCompress
&&
len
(
where
)
!=
0
)
||
if
(
(
what
==
directiveRotateCompress
||
what
==
directiveRotateDisable
)
&&
len
(
where
)
!=
0
)
||
(
what
!=
directiveRotateCompress
&&
len
(
where
)
!=
1
)
{
(
(
what
!=
directiveRotateCompress
&&
what
!=
directiveRotateDisable
)
&&
len
(
where
)
!=
1
)
{
return
invalidRollerParameterEr
r
return
errInvalidRollParamete
r
}
}
var
(
var
(
value
int
value
int
err
error
err
error
)
)
if
what
!=
directiveRotateCompress
{
if
what
!=
directiveRotateCompress
&&
what
!=
directiveRotateDisable
{
value
,
err
=
strconv
.
Atoi
(
where
[
0
])
value
,
err
=
strconv
.
Atoi
(
where
[
0
])
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -96,6 +98,8 @@ func ParseRoller(l *LogRoller, what string, where ...string) error {
...
@@ -96,6 +98,8 @@ func ParseRoller(l *LogRoller, what string, where ...string) error {
}
}
switch
what
{
switch
what
{
case
directiveRotateDisable
:
l
.
Disabled
=
true
case
directiveRotateSize
:
case
directiveRotateSize
:
l
.
MaxSize
=
value
l
.
MaxSize
=
value
case
directiveRotateAge
:
case
directiveRotateAge
:
...
@@ -127,6 +131,7 @@ const (
...
@@ -127,6 +131,7 @@ const (
// defaultRotateKeep is 10 files.
// defaultRotateKeep is 10 files.
defaultRotateKeep
=
10
defaultRotateKeep
=
10
directiveRotateDisable
=
"rotate_disable"
directiveRotateSize
=
"rotate_size"
directiveRotateSize
=
"rotate_size"
directiveRotateAge
=
"rotate_age"
directiveRotateAge
=
"rotate_age"
directiveRotateKeep
=
"rotate_keep"
directiveRotateKeep
=
"rotate_keep"
...
@@ -134,5 +139,7 @@ const (
...
@@ -134,5 +139,7 @@ const (
)
)
// lumberjacks maps log filenames to the logger
// lumberjacks maps log filenames to the logger
// that is being used to keep them rolled/maintained.
// that is being used to keep them rolled/maintained;
var
lumberjacks
=
make
(
map
[
string
]
*
lumberjack
.
Logger
)
// if rolling is disabled, it's just a regular
// *os.File, not a lumberjack
var
lumberjacks
=
make
(
map
[
string
]
io
.
Writer
)
vendor/gopkg.in/natefinch/lumberjack.v2/lumberjack.go
View file @
930ca1cc
...
@@ -104,7 +104,7 @@ type Logger struct {
...
@@ -104,7 +104,7 @@ type Logger struct {
LocalTime
bool
`json:"localtime" yaml:"localtime"`
LocalTime
bool
`json:"localtime" yaml:"localtime"`
// Compress determines if the rotated log files should be compressed
// Compress determines if the rotated log files should be compressed
// using gzip.
// using gzip.
The default is not to perform compression.
Compress
bool
`json:"compress" yaml:"compress"`
Compress
bool
`json:"compress" yaml:"compress"`
size
int64
size
int64
...
...
vendor/manifest
View file @
930ca1cc
...
@@ -733,7 +733,7 @@
...
@@ -733,7 +733,7 @@
"importpath": "gopkg.in/natefinch/lumberjack.v2",
"importpath": "gopkg.in/natefinch/lumberjack.v2",
"repository": "https://gopkg.in/natefinch/lumberjack.v2",
"repository": "https://gopkg.in/natefinch/lumberjack.v2",
"vcs": "git",
"vcs": "git",
"revision": "
df99d62fd42d8b3752c8a42c6723555372c02a03
",
"revision": "
7d6a1875575e09256dc552b4c0e450dcd02bd10e
",
"branch": "v2.0",
"branch": "v2.0",
"notests": true
"notests": true
},
},
...
...
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