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
9b1f36d2
Commit
9b1f36d2
authored
Dec 09, 2012
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shrpx: Color severity level in terminal
Color severity level if stderr refers to a terminal.
parent
bbf6c185
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
4 deletions
+23
-4
src/shrpx.cc
src/shrpx.cc
+1
-0
src/shrpx_config.h
src/shrpx_config.h
+2
-0
src/shrpx_log.cc
src/shrpx_log.cc
+20
-4
No files found.
src/shrpx.cc
View file @
9b1f36d2
...
...
@@ -369,6 +369,7 @@ void fill_default_config()
mod_config
()
->
gid
=
0
;
mod_config
()
->
backend_ipv4
=
false
;
mod_config
()
->
backend_ipv6
=
false
;
mod_config
()
->
tty
=
isatty
(
fileno
(
stderr
));
}
}
// namespace
...
...
src/shrpx_config.h
View file @
9b1f36d2
...
...
@@ -122,6 +122,8 @@ struct Config {
char
*
cacert
;
bool
backend_ipv4
;
bool
backend_ipv6
;
// true if stderr refers to a terminal.
bool
tty
;
};
const
Config
*
get_config
();
...
...
src/shrpx_log.cc
View file @
9b1f36d2
...
...
@@ -33,9 +33,20 @@
namespace
shrpx
{
namespace
{
const
char
*
SEVERITY_STR
[]
=
{
"INFO"
,
"WARN"
,
"ERROR"
,
"FATAL"
};
}
// namespace
namespace
{
const
char
*
SEVERITY_COLOR
[]
=
{
"
\033
[1;32m"
,
// INFO
"
\033
[1;33m"
,
// WARN
"
\033
[1;31m"
,
// ERROR
"
\033
[1;35m"
,
// FATAL
};
}
// namespace
int
Log
::
severity_thres_
=
WARNING
;
...
...
@@ -80,12 +91,17 @@ Log::Log(int severity, const char *filename, int linenum)
Log
::~
Log
()
{
if
(
severity_
>=
severity_thres_
)
{
fprintf
(
stderr
,
"[%s] %s
\n
(%s, line %d)
\n
"
,
SEVERITY_STR
[
severity_
],
stream_
.
str
().
c_str
(),
filename_
,
linenum_
);
fprintf
(
stderr
,
"[%s%s%s] %s
\n
%s(%s:%d)%s
\n
"
,
get_config
()
->
tty
?
SEVERITY_COLOR
[
severity_
]
:
""
,
SEVERITY_STR
[
severity_
],
get_config
()
->
tty
?
"
\033
[0m"
:
""
,
stream_
.
str
().
c_str
(),
get_config
()
->
tty
?
"
\033
[1;30m"
:
""
,
filename_
,
linenum_
,
get_config
()
->
tty
?
"
\033
[0m"
:
""
);
fflush
(
stderr
);
if
(
get_config
()
->
use_syslog
)
{
syslog
(
severity_to_syslog_level
(
severity_
),
"%s (%s
, line
%d)
\n
"
,
syslog
(
severity_to_syslog_level
(
severity_
),
"%s (%s
:
%d)
\n
"
,
stream_
.
str
().
c_str
(),
filename_
,
linenum_
);
}
}
...
...
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