Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
haoqu.ma
/
gotty
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c88cf7a5
authored
Sep 20, 2015
by
Iwasaki Yudai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show RemoteAddr and HTTP status code in log
1 parent
af1a80c9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
app/app.go
app/http_logger.go
app/app.go
View file @
c88cf7a
...
...
@@ -218,7 +218,7 @@ func (app *App) handleWS(w http.ResponseWriter, r *http.Request) {
conn
,
err
:=
app
.
upgrader
.
Upgrade
(
w
,
r
,
nil
)
if
err
!=
nil
{
log
.
Print
(
"Failed to upgrade connection
"
)
log
.
Print
(
"Failed to upgrade connection
: "
+
err
.
Error
()
)
return
}
...
...
@@ -269,8 +269,9 @@ func (app *App) Exit() (firstCall bool) {
func
wrapLogger
(
handler
http
.
Handler
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Printf
(
"%s %s"
,
r
.
Method
,
r
.
URL
.
Path
)
handler
.
ServeHTTP
(
w
,
r
)
rw
:=
&
responseWrapper
{
w
,
200
}
handler
.
ServeHTTP
(
rw
,
r
)
log
.
Printf
(
"%s %d %s %s"
,
r
.
RemoteAddr
,
rw
.
status
,
r
.
Method
,
r
.
URL
.
Path
)
})
}
...
...
app/http_logger.go
0 → 100644
View file @
c88cf7a
package
app
import
(
"bufio"
"net"
"net/http"
)
type
responseWrapper
struct
{
http
.
ResponseWriter
status
int
}
func
(
w
*
responseWrapper
)
WriteHeader
(
status
int
)
{
w
.
status
=
status
w
.
ResponseWriter
.
WriteHeader
(
status
)
}
func
(
w
*
responseWrapper
)
Hijack
()
(
net
.
Conn
,
*
bufio
.
ReadWriter
,
error
)
{
hj
,
_
:=
w
.
ResponseWriter
.
(
http
.
Hijacker
)
w
.
status
=
http
.
StatusSwitchingProtocols
return
hj
.
Hijack
()
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment