Mercurial > projects > mde
diff mde/Init.d @ 18:56a42ec95024
Changes to Init and logging.
Moved an Init function; hence events now depends on Init rather than vice-versa.
Paths and logging set up by Init's static this(). Logging location set at compile time.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 18 Mar 2008 17:51:52 +0000 |
parents | 5f90774ea1ef |
children | db0b48f02b69 |
line wrap: on
line diff
--- a/mde/Init.d Sat Mar 15 15:14:25 2008 +0000 +++ b/mde/Init.d Tue Mar 18 17:51:52 2008 +0000 @@ -16,22 +16,22 @@ /************************************************************************************************** * Initialisation setup and exit cleanup module. * - * This module controls most of the initialisation and deinitialisation of the program. + * This module provides an infrastructure for handling much of the initialisation and + * deinitialisation of the program. It does not, however, provide much of the (de)initialisation + * code; with the exception of that for the logger. *************************************************************************************************/ module mde.Init; import mde.exception; - import mde.options; -import mde.events; -import global = mde.global; -import mde.input.input; +import paths = mde.resource.paths; // tango imports import tango.core.Thread; import tango.core.Exception; import tango.util.log.Log : Log, Logger; import tango.util.log.ConsoleAppender : ConsoleAppender; +import tango.util.log.SwitchingFileAppender : SwitchingFileAppender; import tango.stdc.stringz : fromStringz; /** @@ -42,18 +42,31 @@ */ static this() { - version (mdeTest) {} // test.mdeTest sets up its own root logger + // Find/create paths: + try { + paths.resolvePaths(); + } catch (Exception e) { + throw new InitException ("Resolving paths failed: " ~ e.msg); + } + + // Set up the logger: + version (mdeTest) {} // test.mdeTest sets up its own root logger else { - // For now, just log to the console: + // Where logging is done to is determined at compile-time, currently just via static ifs. Logger root = Log.getRootLogger(); - root.addAppender(new ConsoleAppender); + + static if (true ) { // Log to the console + root.addAppender(new ConsoleAppender); + } + static if (true ) { // Log to files + // Use 2 log files with a maximum size of 1 MB: + root.addAppender (new SwitchingFileAppender (paths.logDir~"/log-.txt", 5)); + } // Set the level here, but set it again once options have been loaded: debug root.setLevel(root.Level.Trace); else root.setLevel(root.Level.Info); } - - Init.addFunc (&miscInit); } static ~this() { @@ -89,11 +102,13 @@ */ this() { + logger.info ("Init: starting"); - logger.info ("Init: starting"); //BEGIN Pre-init (loading options) - // Load options FIRST. Should be fast, most work is probably disk access, - // and it's a really good idea to let the options apply to all other loading. + /* Load options now. Don't load in a thread since: + * Loading should be fast + * Most work is probably disk access + * It's a really good idea to let the options apply to all other loading. */ try { Options.load(); } catch (optionsLoadException e) { @@ -101,6 +116,7 @@ } addCleanupFct (&Options.save); // not strictly cleanup, but needs to be called somewhere + // Now re-set the logging level: Log.getRootLogger.setLevel (cast(Log.Level) Options.misc.logLevel, true); // set the stored log level //END Pre-init @@ -240,18 +256,3 @@ logger.info ("Unittest complete."); } } - -void miscInit () { - /* Some miscellaneous short calls. - * - * Was executed in the main loop, but for the sake of simplicity use another thread. - */ - try { - global.input = new Input(); - global.input.loadConfig (); // (may also create instance) - - addEventsSchedule (); - } catch (Exception e) { - init.setFailure (); // must clean up properly - } -}