charon-cmd: Add --debug argument to set the default log level
This commit is contained in:
@@ -36,6 +36,11 @@
|
|||||||
#include "cmd/cmd_connection.h"
|
#include "cmd/cmd_connection.h"
|
||||||
#include "cmd/cmd_creds.h"
|
#include "cmd/cmd_creds.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default loglevel
|
||||||
|
*/
|
||||||
|
static level_t default_loglevel = LEVEL_CTRL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loglevel configuration
|
* Loglevel configuration
|
||||||
*/
|
*/
|
||||||
@@ -63,7 +68,7 @@ static void dbg_stderr(debug_t group, level_t level, char *fmt, ...)
|
|||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
if (level <= 1)
|
if (level <= default_loglevel)
|
||||||
{
|
{
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
fprintf(stderr, "00[%N] ", debug_names, group);
|
fprintf(stderr, "00[%N] ", debug_names, group);
|
||||||
@@ -280,6 +285,9 @@ static void handle_arguments(int argc, char *argv[], bool simple)
|
|||||||
case CMD_OPT_VERSION:
|
case CMD_OPT_VERSION:
|
||||||
printf("%s, strongSwan %s\n", "charon-cmd", VERSION);
|
printf("%s, strongSwan %s\n", "charon-cmd", VERSION);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
case CMD_OPT_DEBUG:
|
||||||
|
default_loglevel = atoi(optarg);
|
||||||
|
continue;
|
||||||
default:
|
default:
|
||||||
if (simple)
|
if (simple)
|
||||||
{
|
{
|
||||||
@@ -338,7 +346,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
for (group = 0; group < DBG_MAX; group++)
|
for (group = 0; group < DBG_MAX; group++)
|
||||||
{
|
{
|
||||||
levels[group] = LEVEL_CTRL;
|
levels[group] = default_loglevel;
|
||||||
}
|
}
|
||||||
charon->load_loggers(charon, levels, TRUE);
|
charon->load_loggers(charon, levels, TRUE);
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ cmd_option_t cmd_options[CMD_OPT_COUNT] = {
|
|||||||
"print this usage information and exit", {}},
|
"print this usage information and exit", {}},
|
||||||
{ CMD_OPT_VERSION, "version", no_argument, "",
|
{ CMD_OPT_VERSION, "version", no_argument, "",
|
||||||
"show version information and exit", {}},
|
"show version information and exit", {}},
|
||||||
|
{ CMD_OPT_DEBUG, "debug", required_argument, "level",
|
||||||
|
"set the default log level (-1..4, default: 1)", {}},
|
||||||
{ CMD_OPT_HOST, "host", required_argument, "hostname",
|
{ CMD_OPT_HOST, "host", required_argument, "hostname",
|
||||||
"DNS name or address to connect to", {}},
|
"DNS name or address to connect to", {}},
|
||||||
{ CMD_OPT_IDENTITY, "identity", required_argument, "identity",
|
{ CMD_OPT_IDENTITY, "identity", required_argument, "identity",
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ typedef enum cmd_option_type_t cmd_option_type_t;
|
|||||||
enum cmd_option_type_t {
|
enum cmd_option_type_t {
|
||||||
CMD_OPT_HELP,
|
CMD_OPT_HELP,
|
||||||
CMD_OPT_VERSION,
|
CMD_OPT_VERSION,
|
||||||
|
CMD_OPT_DEBUG,
|
||||||
CMD_OPT_HOST,
|
CMD_OPT_HOST,
|
||||||
CMD_OPT_IDENTITY,
|
CMD_OPT_IDENTITY,
|
||||||
CMD_OPT_REMOTE_IDENTITY,
|
CMD_OPT_REMOTE_IDENTITY,
|
||||||
|
|||||||
Reference in New Issue
Block a user