nghttp, nghttpd: Add --color option to force colored log output

This commit is contained in:
Tatsuhiro Tsujikawa 2013-11-01 23:06:53 +09:00
parent 9ee468ce62
commit 1835bda02e
2 changed files with 19 additions and 5 deletions

View File

@ -1619,12 +1619,14 @@ void print_help(std::ostream& out)
<< " is large enough as it is seen as unlimited.\n" << " is large enough as it is seen as unlimited.\n"
<< " -c, --header-table-size=<N>\n" << " -c, --header-table-size=<N>\n"
<< " Specify decoder header table size.\n" << " Specify decoder header table size.\n"
<< " --color Force colored log output.\n"
<< std::endl; << std::endl;
} }
} // namespace } // namespace
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
bool color = false;
while(1) { while(1) {
int flag = 0; int flag = 0;
static option long_options[] = { static option long_options[] = {
@ -1636,8 +1638,6 @@ int main(int argc, char **argv)
{"connection-window-bits", required_argument, nullptr, 'W'}, {"connection-window-bits", required_argument, nullptr, 'W'},
{"get-assets", no_argument, nullptr, 'a'}, {"get-assets", no_argument, nullptr, 'a'},
{"stat", no_argument, nullptr, 's'}, {"stat", no_argument, nullptr, 's'},
{"cert", required_argument, &flag, 1},
{"key", required_argument, &flag, 2},
{"help", no_argument, nullptr, 'h'}, {"help", no_argument, nullptr, 'h'},
{"header", required_argument, nullptr, 'H'}, {"header", required_argument, nullptr, 'H'},
{"data", required_argument, nullptr, 'd'}, {"data", required_argument, nullptr, 'd'},
@ -1647,6 +1647,9 @@ int main(int argc, char **argv)
{"pri", required_argument, nullptr, 'p'}, {"pri", required_argument, nullptr, 'p'},
{"peer-max-concurrent-streams", required_argument, nullptr, 'M'}, {"peer-max-concurrent-streams", required_argument, nullptr, 'M'},
{"header-table-size", required_argument, nullptr, 'c'}, {"header-table-size", required_argument, nullptr, 'c'},
{"cert", required_argument, &flag, 1},
{"key", required_argument, &flag, 2},
{"color", no_argument, &flag, 3},
{nullptr, 0, nullptr, 0 } {nullptr, 0, nullptr, 0 }
}; };
int option_index = 0; int option_index = 0;
@ -1774,6 +1777,10 @@ int main(int argc, char **argv)
// key option // key option
config.keyfile = optarg; config.keyfile = optarg;
break; break;
case 3:
// color option
color = true;
break;
} }
break; break;
default: default:
@ -1781,7 +1788,7 @@ int main(int argc, char **argv)
} }
} }
set_color_output(isatty(fileno(stdout))); set_color_output(color || isatty(fileno(stdout)));
struct sigaction act; struct sigaction act;
memset(&act, 0, sizeof(struct sigaction)); memset(&act, 0, sizeof(struct sigaction));

View File

@ -76,6 +76,7 @@ void print_help(std::ostream& out)
<< " -f, --no-flow-control\n" << " -f, --no-flow-control\n"
<< " Disables connection and stream level flow\n" << " Disables connection and stream level flow\n"
<< " controls.\n" << " controls.\n"
<< " --color Force colored log output.\n"
<< " -h, --help Print this help.\n" << " -h, --help Print this help.\n"
<< std::endl; << std::endl;
} }
@ -84,6 +85,7 @@ void print_help(std::ostream& out)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Config config; Config config;
bool color = false;
while(1) { while(1) {
int flag = 0; int flag = 0;
static option long_options[] = { static option long_options[] = {
@ -92,8 +94,9 @@ int main(int argc, char **argv)
{"help", no_argument, nullptr, 'h'}, {"help", no_argument, nullptr, 'h'},
{"verbose", no_argument, nullptr, 'v'}, {"verbose", no_argument, nullptr, 'v'},
{"verify-client", no_argument, nullptr, 'V'}, {"verify-client", no_argument, nullptr, 'V'},
{"no-tls", no_argument, &flag, 1},
{"no-flow-control", no_argument, nullptr, 'f'}, {"no-flow-control", no_argument, nullptr, 'f'},
{"no-tls", no_argument, &flag, 1},
{"color", no_argument, &flag, 2},
{nullptr, 0, nullptr, 0} {nullptr, 0, nullptr, 0}
}; };
int option_index = 0; int option_index = 0;
@ -128,6 +131,10 @@ int main(int argc, char **argv)
// no-tls option // no-tls option
config.no_tls = true; config.no_tls = true;
break; break;
case 2:
// color option
color = true;
break;
} }
break; break;
default: default:
@ -162,7 +169,7 @@ int main(int argc, char **argv)
config.htdocs = "./"; config.htdocs = "./";
} }
set_color_output(isatty(fileno(stdout))); set_color_output(color || isatty(fileno(stdout)));
struct sigaction act; struct sigaction act;
memset(&act, 0, sizeof(struct sigaction)); memset(&act, 0, sizeof(struct sigaction));