Skip to content
Snippets Groups Projects
Commit 28afd0d7 authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Update logging class to be a singleton

Should prevent having large numbers of identical file descriptors,
when calling logging from multiple files.
parent fd63e8a2
Branches
No related merge requests found
...@@ -10,7 +10,7 @@ const { Logging, testLogLevels } = require('./src/logging.js'); ...@@ -10,7 +10,7 @@ const { Logging, testLogLevels } = require('./src/logging.js');
// Initialize logging. // Initialize logging.
let logger = new Logging('./logging/'); let logger = Logging.init('./logging/');
/** /**
......
...@@ -18,9 +18,36 @@ const { getCurrentDate } = require('./helper_functions.js'); ...@@ -18,9 +18,36 @@ const { getCurrentDate } = require('./helper_functions.js');
/** /**
* Logging class. * "Fake" logging class used exclusively to initialize our real logging class.
* Helps keep our real singleton class private.
*
* This is necessary because JavaScript doesn't seem to allow constructor overloading or private constructors.
*/ */
class Logging { class Logging {
/**
* Class Constructor.
*/
constructor() {
throw new Error('Initialize class with "Logging.init()".');
}
/**
* Method to initialize our singleton class.
*/
static init(logging_dir) {
if ( ! Logging.instance ) {
Logging.instance = new LoggingClass(logging_dir);
}
return Logging.instance;
}
}
/**
* Real logging class.
*/
class LoggingClass {
test_var = 'test_var string'; test_var = 'test_var string';
#console_debug = 'debug test'; #console_debug = 'debug test';
#debug_file_logger; #debug_file_logger;
...@@ -234,7 +261,6 @@ function testLogLevels(logger) { ...@@ -234,7 +261,6 @@ function testLogLevels(logger) {
logger.warning('WARNING level test.'); logger.warning('WARNING level test.');
logger.error('ERROR level test.'); logger.error('ERROR level test.');
logger.log('Log/default level test.'); logger.log('Log/default level test.');
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment