@@ -34,6 +34,9 @@ struct config_data cfg = {
3434 .runtime_us = DEFAULT_RUNTIME ,
3535 .pidfile_fd = -1 ,
3636 .ev_backend = EVFLAG_AUTO ,
37+ #ifdef LIBCURL
38+ .access_log_mode = 3 ,
39+ #endif
3740};
3841struct program_data prg ;
3942
@@ -71,6 +74,9 @@ static void usage(const char *program_name, bool_t flag_verbose)
7174 (void )printf (" -F, --pidfile=FILE Specifies a file to write the process-id to.\n" );
7275 (void )printf (" -h, --help Show this text.\n" );
7376 (void )printf (" -i, --monitor-interval=TIME Set the monitor interval (default: %s).\n" , str_delay (DEFAULT_MONITOR_INTERVAL ));
77+ #ifdef HAVE_LIBCURL
78+ (void )printf (" -L, --access-log=MODE Specify the mode of access logging (default: \"ALL\").\n" );
79+ #endif
7480 (void )printf (" -l, --logfile=[MODE:]FILE Log all messages to logfile (default: stdout/stderr).\n" );
7581 (void )printf (" -m, --max-frame-size=VALUE Specify the maximum frame size (default: %d bytes).\n" , DEFAULT_MAX_FRAME_SIZE );
7682 (void )printf (" -n, --num-workers=VALUE Specify the number of workers (default: %d).\n" , DEFAULT_NUM_WORKERS );
@@ -91,6 +97,7 @@ static void usage(const char *program_name, bool_t flag_verbose)
9197 (void )printf ("for the mode, then line buffering is used when writing to the log file.\n\n" );
9298 (void )printf ("The time delay/interval is specified in milliseconds by default, but can be\n" );
9399 (void )printf ("in any other unit if the number is suffixed by a unit (us, ms, s, m, h, d).\n\n" );
100+ (void )printf ("Access logging modes are 'NONE', 'ERROR', 'SUCCESS', 'ALL'.\n\n" );
94101 (void )printf ("Copyright 2018-2020 HAProxy Technologies\n" );
95102 (void )printf ("SPDX-License-Identifier: GPL-2.0-or-later\n\n" );
96103 } else {
@@ -326,6 +333,55 @@ static int getopt_set_ports(const char *ports, int *range)
326333}
327334
328335
336+ /***
337+ * NAME
338+ * getopt_set_access_log_mode -
339+ *
340+ * ARGUMENTS
341+ * mode_txt -
342+ * mode_val -
343+ *
344+ * DESCRIPTION
345+ * -
346+ *
347+ * RETURN VALUE
348+ * -
349+ */
350+ static int getopt_set_access_log_mode (const char * mode_txt , int * mode_val )
351+ {
352+ int retval = FUNC_RET_ERROR , mode = 0 ;
353+
354+ DBG_FUNC (NULL , "\"%s\", %p" , mode_txt , mode_val );
355+
356+ if (* mode_txt == 'A' || * mode_txt == 'a' ) {
357+ mode = 3 ;
358+ retval = FUNC_RET_OK ;
359+ }
360+ else if (* mode_txt == 'E' || * mode_txt == 'e' ) {
361+ mode = 2 ;
362+ retval = FUNC_RET_OK ;
363+ }
364+ else if (* mode_txt == 'S' || * mode_txt == 's' ) {
365+ mode = 1 ;
366+ retval = FUNC_RET_OK ;
367+ }
368+ else if (* mode_txt == 'N' || * mode_txt == 'n' ) {
369+ mode = 0 ;
370+ retval = FUNC_RET_OK ;
371+ }
372+ else
373+ (void )fprintf (stderr , "ERROR: access log mode must be one of 'ALL', 'ERROR', 'SUCCESS', or 'NONE'\n" );
374+
375+ /* If everything is fine, set the mode. */
376+ if (_OK (retval )) {
377+ * mode_val = mode ;
378+ W_DBG (NOTICE , NULL , " mode set to %d" , mode );
379+ }
380+
381+ return retval ;
382+ }
383+
384+
329385/***
330386 * NAME
331387 * main -
@@ -360,6 +416,7 @@ int main(int argc, char **argv, char **envp __maybe_unused)
360416 { "runtime" , required_argument , NULL , 'r' },
361417 { "processing-delay" , required_argument , NULL , 't' },
362418#ifdef HAVE_LIBCURL
419+ { "access-log" , required_argument , NULL , 'L' },
363420 { "mirror-url" , required_argument , NULL , 'u' },
364421 { "mirror-interface" , required_argument , NULL , 'I' },
365422 { "mirror-local-port" , required_argument , NULL , 'P' },
@@ -422,6 +479,8 @@ int main(int argc, char **argv, char **envp __maybe_unused)
422479 else if (c == 't' )
423480 flag_error |= _OK (getopt_set_time (optarg , & (cfg .processing_delay_us ), 0 , TIMEINT_S (1 ))) ? 0 : 1 ;
424481#ifdef HAVE_LIBCURL
482+ else if (c == 'L')
483+ flag_error |= _OK (getopt_set_access_log_mode (optarg , & (cfg .access_log_mode ))) ? 0 : 1 ;
425484 else if (c == 'u')
426485 mir_url = optarg ;
427486 else if (c == 'I ')
0 commit comments