mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-17 09:42:38 +03:00
Allow verbose logging to be directed to a file
This commit is contained in:
parent
20d29c0537
commit
4324bf535f
35
utils/log.c
35
utils/log.c
@ -26,8 +26,12 @@
|
||||
|
||||
#include "utils/log.h"
|
||||
|
||||
/** flag to enable verbose logging */
|
||||
bool verbose_log = false;
|
||||
|
||||
/** The stream to which logging is sent */
|
||||
static FILE *logf;
|
||||
|
||||
nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
|
||||
{
|
||||
nserror ret = NSERROR_OK;
|
||||
@ -37,6 +41,11 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
|
||||
(argv[1][1] == 'v') &&
|
||||
(argv[1][2] == 0)) {
|
||||
int argcmv;
|
||||
|
||||
/* verbose logging to stderr */
|
||||
logf = stderr;
|
||||
|
||||
/* remove -v from argv list */
|
||||
for (argcmv = 2; argcmv < (*pargc); argcmv++) {
|
||||
argv[argcmv - 1] = argv[argcmv];
|
||||
}
|
||||
@ -44,12 +53,36 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
|
||||
|
||||
/* ensure we actually show logging */
|
||||
verbose_log = true;
|
||||
} else if (((*pargc) > 2) &&
|
||||
(argv[1][0] == '-') &&
|
||||
(argv[1][1] == 'V') &&
|
||||
(argv[1][2] == 0)) {
|
||||
int argcmv;
|
||||
|
||||
/* verbose logging to file */
|
||||
logf = fopen(argv[2], "a+");
|
||||
|
||||
/* remove -V and filename from argv list */
|
||||
for (argcmv = 3; argcmv < (*pargc); argcmv++) {
|
||||
argv[argcmv - 1] = argv[argcmv];
|
||||
}
|
||||
(*pargc)--;
|
||||
|
||||
if (logf == NULL) {
|
||||
/* could not open log file for output */
|
||||
ret = NSERROR_NOT_FOUND;
|
||||
verbose_log = false;
|
||||
} else {
|
||||
|
||||
/* ensure we actually show logging */
|
||||
verbose_log = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* ensure output file handle is correctly configured */
|
||||
if ((verbose_log == true) &&
|
||||
(ensure != NULL) &&
|
||||
(ensure(stderr) == false)) {
|
||||
(ensure(logf) == false)) {
|
||||
/* failed to ensure output configuration */
|
||||
ret = NSERROR_INIT_FAILED;
|
||||
verbose_log = false;
|
||||
|
Loading…
Reference in New Issue
Block a user