Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
90eebbc8
Commit
90eebbc8
authored
Dec 09, 2012
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shrpx: Log status code, method, path and HTTP version in accesslog
parent
6ef9b743
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
8 deletions
+89
-8
src/shrpx_accesslog.cc
src/shrpx_accesslog.cc
+67
-8
src/shrpx_accesslog.h
src/shrpx_accesslog.h
+4
-0
src/shrpx_https_upstream.cc
src/shrpx_https_upstream.cc
+9
-0
src/shrpx_spdy_upstream.cc
src/shrpx_spdy_upstream.cc
+9
-0
No files found.
src/shrpx_accesslog.cc
View file @
90eebbc8
...
...
@@ -31,6 +31,7 @@
#include <cstring>
#include "shrpx_config.h"
#include "shrpx_downstream.h"
namespace
shrpx
{
...
...
@@ -55,10 +56,10 @@ void upstream_connect(const std::string& client_ip)
{
char
datestr
[
64
];
get_datestr
(
datestr
);
fprintf
(
stderr
,
"
[%s] Accepted %s
\n
"
,
datestr
,
client_ip
.
c_str
()
);
fprintf
(
stderr
,
"
%s [%s] ACCEPT
\n
"
,
client_ip
.
c_str
(),
datestr
);
fflush
(
stderr
);
if
(
get_config
()
->
use_syslog
)
{
syslog
(
LOG_INFO
,
"
Accepted %s
\n
"
,
client_ip
.
c_str
());
syslog
(
LOG_INFO
,
"
%s ACCEPT
\n
"
,
client_ip
.
c_str
());
}
}
...
...
@@ -66,11 +67,11 @@ void upstream_spdy_stream(const std::string& client_ip, int32_t stream_id)
{
char
datestr
[
64
];
get_datestr
(
datestr
);
fprintf
(
stderr
,
"
[%s] %s SPDY stream_id=%d
\n
"
,
datestr
,
client_ip
.
c_str
()
,
fprintf
(
stderr
,
"
%s [%s] SYN_STREAM %d
\n
"
,
client_ip
.
c_str
(),
datestr
,
stream_id
);
fflush
(
stderr
);
if
(
get_config
()
->
use_syslog
)
{
syslog
(
LOG_INFO
,
"%s S
PDY stream_id=
%d
\n
"
,
client_ip
.
c_str
(),
stream_id
);
syslog
(
LOG_INFO
,
"%s S
YN_STREAM
%d
\n
"
,
client_ip
.
c_str
(),
stream_id
);
}
}
...
...
@@ -79,12 +80,70 @@ void upstream_spdy_stream_close(const std::string& client_ip,
{
char
datestr
[
64
];
get_datestr
(
datestr
);
fprintf
(
stderr
,
"
[%s] %s SPDY stream_id=%d close
d
\n
"
,
datestr
,
client_ip
.
c_str
()
,
stream_id
);
fprintf
(
stderr
,
"
%s [%s] STREAM_CLOSE %
d
\n
"
,
client_ip
.
c_str
(),
datestr
,
stream_id
);
fflush
(
stderr
);
if
(
get_config
()
->
use_syslog
)
{
syslog
(
LOG_INFO
,
"%s SPDY stream_id=%d closed
\n
"
,
client_ip
.
c_str
(),
stream_id
);
syslog
(
LOG_INFO
,
"%s STREAM_CLOSE %d
\n
"
,
client_ip
.
c_str
(),
stream_id
);
}
}
namespace
{
const
char
*
status_code_color
(
int
status_code
)
{
if
(
status_code
<=
199
)
{
return
"
\033
[1;36m"
;
}
else
if
(
status_code
<=
299
)
{
return
"
\033
[1;32m"
;
}
else
if
(
status_code
<=
399
)
{
return
"
\033
[1;34m"
;
}
else
if
(
status_code
<=
499
)
{
return
"
\033
[1;31m"
;
}
else
if
(
status_code
<=
599
)
{
return
"
\033
[1;35m"
;
}
else
{
return
""
;
}
}
}
// namespace
void
upstream_response
(
const
std
::
string
&
client_ip
,
int
status_code
,
Downstream
*
downstream
)
{
char
datestr
[
64
];
get_datestr
(
datestr
);
if
(
downstream
)
{
fprintf
(
stderr
,
"%s%s [%s] %d%s %d
\"
%s %s HTTP/%u.%u
\"\n
"
,
get_config
()
->
tty
?
status_code_color
(
status_code
)
:
""
,
client_ip
.
c_str
(),
datestr
,
status_code
,
get_config
()
->
tty
?
"
\033
[0m"
:
""
,
downstream
->
get_stream_id
(),
downstream
->
get_request_method
().
c_str
(),
downstream
->
get_request_path
().
c_str
(),
downstream
->
get_request_major
(),
downstream
->
get_request_minor
());
fflush
(
stderr
);
if
(
get_config
()
->
use_syslog
)
{
syslog
(
LOG_INFO
,
"%s %d %d
\"
%s %s HTTP/%u.%u
\"\n
"
,
client_ip
.
c_str
(),
status_code
,
downstream
->
get_stream_id
(),
downstream
->
get_request_method
().
c_str
(),
downstream
->
get_request_path
().
c_str
(),
downstream
->
get_request_major
(),
downstream
->
get_request_minor
());
}
}
else
{
fprintf
(
stderr
,
"%s%s [%s] %d%s 0
\"
-
\"\n
"
,
get_config
()
->
tty
?
status_code_color
(
status_code
)
:
""
,
client_ip
.
c_str
(),
datestr
,
status_code
,
get_config
()
->
tty
?
"
\033
[0m"
:
""
);
if
(
get_config
()
->
use_syslog
)
{
syslog
(
LOG_INFO
,
"%s %d 0
\"
-
\"\n
"
,
client_ip
.
c_str
(),
status_code
);
}
fflush
(
stderr
);
}
}
...
...
src/shrpx_accesslog.h
View file @
90eebbc8
...
...
@@ -31,10 +31,14 @@
namespace
shrpx
{
class
Downstream
;
void
upstream_connect
(
const
std
::
string
&
client_ip
);
void
upstream_spdy_stream
(
const
std
::
string
&
client_ip
,
int32_t
stream_id
);
void
upstream_spdy_stream_close
(
const
std
::
string
&
client_ip
,
int32_t
stream_id
);
void
upstream_response
(
const
std
::
string
&
client_ip
,
int
status_code
,
Downstream
*
downstream
);
}
// namespace shrpx
...
...
src/shrpx_https_upstream.cc
View file @
90eebbc8
...
...
@@ -35,6 +35,7 @@
#include "shrpx_http.h"
#include "shrpx_config.h"
#include "shrpx_error.h"
#include "shrpx_accesslog.h"
#include "util.h"
using
namespace
spdylay
;
...
...
@@ -544,6 +545,10 @@ int HttpsUpstream::error_reply(int status_code)
if
(
downstream
)
{
downstream
->
set_response_state
(
Downstream
::
MSG_COMPLETE
);
}
if
(
get_config
()
->
accesslog
)
{
upstream_response
(
this
->
get_client_handler
()
->
get_ipaddr
(),
status_code
,
downstream
);
}
return
0
;
}
...
...
@@ -647,6 +652,10 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
ULOG
(
FATAL
,
this
)
<<
"evbuffer_add() failed"
;
return
-
1
;
}
if
(
get_config
()
->
accesslog
)
{
upstream_response
(
this
->
get_client_handler
()
->
get_ipaddr
(),
downstream
->
get_response_http_status
(),
downstream
);
}
return
0
;
}
...
...
src/shrpx_spdy_upstream.cc
View file @
90eebbc8
...
...
@@ -698,6 +698,10 @@ int SpdyUpstream::error_reply(Downstream *downstream, int status_code)
<<
spdylay_strerror
(
rv
);
DIE
();
}
if
(
get_config
()
->
accesslog
)
{
upstream_response
(
get_client_handler
()
->
get_ipaddr
(),
status_code
,
downstream
);
}
return
0
;
}
...
...
@@ -795,6 +799,11 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream)
ULOG
(
FATAL
,
this
)
<<
"spdylay_submit_response() failed"
;
return
-
1
;
}
if
(
get_config
()
->
accesslog
)
{
upstream_response
(
get_client_handler
()
->
get_ipaddr
(),
downstream
->
get_response_http_status
(),
downstream
);
}
return
0
;
}
...
...
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