move the logging initialisation out to be call by frontends

This allows each frontend to pass a distinct callback to configure the
output file stream appropriately for their use.
This commit is contained in:
Vincent Sanders 2013-05-23 11:50:57 +01:00
parent 12ff7a47f4
commit 35dacc3671
12 changed files with 128 additions and 40 deletions

View File

@ -929,6 +929,11 @@ int main(int argc, char** argv)
amiga_plugin_hack_init();
amiga_datatypes_init();
/* initialise logging. Not fatal if it fails but not much we
* can do about it either.
*/
nslog_init(NULL, &argc, argv);
netsurf_init(&argc, &argv, current_user_options, messages);
amiga_icon_init();

View File

@ -1037,6 +1037,7 @@ int main(int argc, char** argv)
nsurl *url;
nserror error;
/* @todo logging file descriptor update belongs in a nslog_init callback */
setbuf(stderr, NULL);
setbuf(stdout, NULL);
#ifdef WITH_DBG_LOGFILE
@ -1053,6 +1054,11 @@ int main(int argc, char** argv)
atari_find_resource((char*)&messages, "messages", "res/messages");
atari_find_resource((char*)&options, "Choices", "Choices");
/* initialise logging - not fatal if it fails but not much we can
* do about it
*/
nslog_init(NULL, &argc, argv);
LOG(("Initialising core..."));
netsurf_init(&argc, &argv, options, messages);

View File

@ -398,11 +398,20 @@ static void gui_init2(int argc, char** argv)
}
}
/**
* Ensures output logging stream is correctly configured
*/
static bool nslog_stream_configure(FILE *fptr)
{
/* set log stream to be non-buffering */
setbuf(fptr, NULL);
return true;
}
/** Normal entry point from OS */
int main(int argc, char** argv)
{
setbuf(stderr, NULL);
BPath options;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) {
options.Append("x-vnd.NetSurf");
@ -416,11 +425,16 @@ int main(int argc, char** argv)
const char* messages = "/boot/apps/netsurf/res/en/Messages";
/* initialise logging. Not fatal if it fails but not much we
* can do about it either.
*/
nslog_init(nslog_stream_configure, &argc, argv);
/* initialise netsurf */
netsurf_init(&argc, &argv, options.Path(), messages);
gui_init(argc, argv);
gui_init2(argc, argv);
gui_init(argc, argv);
gui_init2(argc, argv);
netsurf_main_loop();
@ -432,8 +446,6 @@ int main(int argc, char** argv)
/** called when replicated from NSBaseView::Instantiate() */
int gui_init_replicant(int argc, char** argv)
{
setbuf(stderr, NULL);
BPath options;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) {
options.Append("x-vnd.NetSurf");
@ -441,6 +453,11 @@ int gui_init_replicant(int argc, char** argv)
const char* messages = "/boot/apps/netsurf/res/en/Messages";
/* initialise logging. Not fatal if it fails but not much we
* can do about it either.
*/
nslog_init(nslog_stream_configure, &argc, argv);
/* initialise netsurf */
netsurf_init(&argc, &argv, options.Path(), messages);

View File

@ -182,6 +182,11 @@ int main( int argc, char **argv )
const char * const messages = [[[NSBundle mainBundle] pathForResource: @"Messages" ofType: @""] UTF8String];
const char * const options = cocoa_get_options_file();
/* initialise logging. Not fatal if it fails but not much we
* can do about it either.
*/
nslog_init(NULL, &argc, argv);
netsurf_init(&argc, &argv, options, messages);
/* Initialise filename allocator */

View File

@ -64,10 +64,6 @@ struct form_control;
#include "desktop/search.h"
#include "utils/errors.h"
/** \todo remove these when each frontend calls nslog_init */
#include <stdio.h>
bool nslog_ensure(FILE *fptr);
void gui_poll(bool active);
void gui_quit(void);

View File

@ -143,15 +143,6 @@ nserror netsurf_init(int *pargc,
signal(SIGPIPE, SIG_IGN);
#endif
#ifndef HAVE_STDOUT
ret = nslog_init(nslog_ensure, pargc, *pargv);
#else
ret = nslog_init(NULL, pargc, *pargv);
#endif
if (ret != NSERROR_OK)
return ret;
LOG(("version '%s'", netsurf_version));
if (uname(&utsname) < 0)
LOG(("Failed to extract machine information"));

View File

@ -516,6 +516,17 @@ gui_init(int argc, char** argv)
urldb_load_cookies(nsoption_charp(cookie_file));
}
/**
* Ensures output logging stream is correctly configured
*/
static bool nslog_stream_configure(FILE *fptr)
{
/* set log stream to be non-buffering */
setbuf(fptr, NULL);
return true;
}
/** Entry point from OS.
*
* /param argc The number of arguments in the string vector.
@ -531,13 +542,16 @@ main(int argc, char** argv)
nsurl *url;
nserror error;
setbuf(stderr, NULL);
respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH);
options = filepath_find(respaths, "Choices");
messages = filepath_find(respaths, "messages");
/* initialise logging. Not fatal if it fails but not much we
* can do about it either.
*/
nslog_init(nslog_stream_configure, &argc, argv);
netsurf_init(&argc, &argv, options, messages);
free(messages);

View File

@ -514,6 +514,17 @@ static void nsgtk_check_homedir(void)
}
}
/**
* Ensures output logging stream is correctly configured
*/
static bool nslog_stream_configure(FILE *fptr)
{
/* set log stream to be non-buffering */
setbuf(fptr, NULL);
return true;
}
/**
* Main entry point from OS.
*/
@ -529,12 +540,14 @@ int main(int argc, char** argv)
gtk_init(&argc, &argv);
/* set standard error to be non-buffering */
setbuf(stderr, NULL);
options = filepath_find(respaths, "Choices");
messages = filepath_find(respaths, "Messages");
/* initialise logging. Not fatal if it fails but not much we
* can do about it either.
*/
nslog_init(nslog_stream_configure, &argc, argv);
netsurf_init(&argc, &argv, options, messages);
free(messages);

View File

@ -97,6 +97,17 @@ void gui_options_init_defaults(void)
/* Set defaults for absent option strings */
}
/**
* Ensures output logging stream is correctly configured
*/
static bool nslog_stream_configure(FILE *fptr)
{
/* set log stream to be non-buffering */
setbuf(fptr, NULL);
return true;
}
int
main(int argc, char **argv)
{
@ -115,6 +126,11 @@ main(int argc, char **argv)
options = filepath_find(respaths, "Choices");
messages = filepath_find(respaths, "Messages");
/* initialise logging. Not fatal if it fails but not much we can do
* about it either.
*/
nslog_init(nslog_stream_configure, &argc, argv);
netsurf_init(&argc, &argv, options, messages);
free(messages);

View File

@ -799,6 +799,17 @@ static void gui_init2(int argc, char** argv)
free(url);
}
/**
* Ensures output logging stream is correctly configured
*/
static bool nslog_stream_configure(FILE *fptr)
{
/* set log stream to be non-buffering */
setbuf(fptr, NULL);
return true;
}
/** Normal entry point from OS */
int main(int argc, char** argv)
{
@ -809,8 +820,6 @@ int main(int argc, char** argv)
int used = -1; /* slightly better with older OSLib versions */
os_error *error;
setbuf(stderr, NULL);
/* Consult NetSurf$Logging environment variable to decide if logging
* is required. */
error = xos_read_var_val_size("NetSurf$Logging", 0, os_VARTYPE_STRING,
@ -828,6 +837,11 @@ int main(int argc, char** argv)
}
}
/* initialise logging. Not fatal if it fails but not much we
* can do about it either.
*/
nslog_init(nslog_stream_configure, &argc, argv);
/* Pass a NULL pointer for Messages path, because until the Choices
* are loaded in netsurf_init, we don't know the Messages path. */
netsurf_init(&argc, &argv, "NetSurf:Choices", NULL);

View File

@ -43,15 +43,17 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv)
/* ensure we actually show logging */
verbose_log = true;
/* ensure stderr is available */
if (ensure != NULL) {
if (ensure(stderr) == false) {
/* failed to ensure output */
ret = NSERROR_INIT_FAILED;
}
}
}
/* ensure output file handle is correctly configured */
if ((verbose_log == true) &&
(ensure != NULL) &&
(ensure(stderr) == false)) {
/* failed to ensure output configuration */
ret = NSERROR_INIT_FAILED;
verbose_log = false;
}
return ret;
}

View File

@ -66,9 +66,9 @@ void gui_quit(void)
}
/**
* Ensures output stdio stream is available
* Ensures output logging stream is available
*/
bool nslog_ensure(FILE *fptr)
static bool nslog_ensure(FILE *fptr)
{
/* mwindows compile flag normally invalidates standard io unless
* already redirected
@ -136,8 +136,17 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
options_file_location = filepath_find(respaths, "preferences");
/* initialise logging - not fatal if it fails but not much we
* can do about it
*/
nslog_init(nslog_ensure, &argc, argv);
/* initialise netsurf */
netsurf_init(&argc, &argv, options_file_location, messages);
ret = netsurf_init(&argc, &argv, options_file_location, messages);
if (ret != NSERROR_OK) {
free(options_file_location);
return 1;
}
free(messages);