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
e6063fb2
Commit
e6063fb2
authored
Jan 29, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved logging middleware into its own package
parent
1e4baa53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
11 deletions
+14
-11
middleware/log/log.go
middleware/log/log.go
+14
-11
No files found.
middleware/log.go
→
middleware/log
/log
.go
View file @
e6063fb2
package
middleware
package
log
import
(
"log"
"net/http"
"os"
"github.com/mholt/caddy/middleware"
)
func
RequestLog
(
p
parser
)
Middleware
{
// New instantiates a new instance of logging middleware.
func
New
(
c
middleware
.
Controller
)
(
middleware
.
Middleware
,
error
)
{
var
logWhat
,
outputFile
,
format
string
var
logger
*
log
.
Logger
for
p
.
Next
()
{
p
.
Args
(
&
logWhat
,
&
outputFile
,
&
format
)
for
c
.
Next
()
{
c
.
Args
(
&
logWhat
,
&
outputFile
,
&
format
)
if
logWhat
==
""
{
return
p
.
ArgErr
()
return
nil
,
c
.
ArgErr
()
}
if
outputFile
==
""
{
outputFile
=
defaultLogFilename
...
...
@@ -30,7 +33,7 @@ func RequestLog(p parser) Middleware {
}
// Open the log file for writing when the server starts
p
.
Startup
(
func
()
error
{
c
.
Startup
(
func
()
error
{
var
err
error
var
file
*
os
.
File
...
...
@@ -51,17 +54,17 @@ func RequestLog(p parser) Middleware {
return
func
(
next
http
.
HandlerFunc
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
sw
:=
n
ewResponseRecorder
(
w
)
sw
:=
middleware
.
N
ewResponseRecorder
(
w
)
next
(
sw
,
r
)
rep
:=
n
ewReplacer
(
r
,
sw
)
logger
.
Println
(
rep
.
r
eplace
(
format
))
rep
:=
middleware
.
N
ewReplacer
(
r
,
sw
)
logger
.
Println
(
rep
.
R
eplace
(
format
))
}
}
}
,
nil
}
const
(
defaultLogFilename
=
"access.log"
commonLogFormat
=
`{remote} `
+
e
mptyStringReplacer
+
` [{when}] "{method} {uri} {proto}" {status} {size}`
commonLogFormat
=
`{remote} `
+
middleware
.
E
mptyStringReplacer
+
` [{when}] "{method} {uri} {proto}" {status} {size}`
combinedLogFormat
=
commonLogFormat
+
` "{>Referer}" "{>User-Agent}"`
defaultReqLogFormat
=
commonLogFormat
)
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