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
710f3804
Commit
710f3804
authored
May 11, 2017
by
Tw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log: allow additional prefix/suffix with predefined format
Signed-off-by:
Tw
<
tw19881113@gmail.com
>
parent
958abcfa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
8 deletions
+24
-8
caddyhttp/log/setup.go
caddyhttp/log/setup.go
+4
-8
caddyhttp/log/setup_test.go
caddyhttp/log/setup_test.go
+20
-0
No files found.
caddyhttp/log/setup.go
View file @
710f3804
package
log
import
(
"strings"
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddyhttp/httpserver"
)
...
...
@@ -75,14 +77,8 @@ func logParse(c *caddy.Controller) ([]*Rule, error) {
format
:=
DefaultLogFormat
if
len
(
args
)
>
2
{
switch
args
[
2
]
{
case
"{common}"
:
format
=
CommonLogFormat
case
"{combined}"
:
format
=
CombinedLogFormat
default
:
format
=
args
[
2
]
}
format
=
strings
.
Replace
(
args
[
2
],
"{common}"
,
CommonLogFormat
,
-
1
)
format
=
strings
.
Replace
(
format
,
"{combined}"
,
CombinedLogFormat
,
-
1
)
}
rules
=
appendEntry
(
rules
,
args
[
0
],
&
Entry
{
...
...
caddyhttp/log/setup_test.go
View file @
710f3804
...
...
@@ -124,6 +124,16 @@ func TestLogParse(t *testing.T) {
Format
:
CommonLogFormat
,
}},
}}},
{
`log /myapi log.txt "prefix {common} suffix"`
,
false
,
[]
Rule
{{
PathScope
:
"/myapi"
,
Entries
:
[]
*
Entry
{{
Log
:
&
httpserver
.
Logger
{
Output
:
"log.txt"
,
Roller
:
httpserver
.
DefaultLogRoller
(),
},
Format
:
"prefix "
+
CommonLogFormat
+
" suffix"
,
}},
}}},
{
`log /test accesslog.txt {combined}`
,
false
,
[]
Rule
{{
PathScope
:
"/test"
,
Entries
:
[]
*
Entry
{{
...
...
@@ -134,6 +144,16 @@ func TestLogParse(t *testing.T) {
Format
:
CombinedLogFormat
,
}},
}}},
{
`log /test accesslog.txt "prefix {combined} suffix"`
,
false
,
[]
Rule
{{
PathScope
:
"/test"
,
Entries
:
[]
*
Entry
{{
Log
:
&
httpserver
.
Logger
{
Output
:
"accesslog.txt"
,
Roller
:
httpserver
.
DefaultLogRoller
(),
},
Format
:
"prefix "
+
CombinedLogFormat
+
" suffix"
,
}},
}}},
{
`log /api1 log.txt
log /api2 accesslog.txt {combined}`
,
false
,
[]
Rule
{{
PathScope
:
"/api1"
,
...
...
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