Log Service Factory
Overview
The LogServiceFactory is a utility class that provides a centralized way to create and manage LogService instances in the DIGIDECK platform. It provides methods to create new LogService instances with configurable options.
API Reference
Methods
createLogService(options)
Creates a new instance of LogService with the specified configuration options.
const logService = LogServiceFactory.createLogService({
namespace: 'MyAwesomeClass',
isLogDebugEnabled: true,
isLogErrorEnabled: true
});
logService.logDebug('This is a debug log, and should print to the console!')
Parameters:
options(Object, optional): Configuration options for the LogServicenamespace(String, optional): The namespace for the loggerisLogDebugEnabled(Boolean, optional): Whether debug logging is enabled. Defaults to true in develop environment, false in all other envs.isLogErrorEnabled(Boolean, optional): Whether error logging is enabled. Defaults to true in all environments.
Returns:
- A new instance of
LogService
LogService Instance
The LogService instance created by the factory provides logging functionality with configurable debug and error logging.
Methods
logDebug(message)
Description
- Logs a debug message if debug logging is enabled via
isLogDebugEnabled(Enabled by default in develop environment. Disabled in other other envs)
Parameters
message(String): The debug message to logdata(Object) Optional: Additional data to log
`logError(errorMessage, data)
Parameters
errorMessage(String): The error message to logdata(Object) Optional: Additional data to log
Description
- Logs an error message if error loggind is enabled via
isLogErrorEnabledoption. (Enabled by default in all environments);
Complete Code Examples
const logService = LogServiceFactory.createLogService({ namespace: 'MyAwesomeComponentApp', isLogDebugEnabled: true });
logService.logDebug('testing log debugs!', { additionalData: 'here' });
// should output to the console:
// MyAwesomeComponentApp - Debug: testing log debugs! { additionalData: 'here' }
logService.logError('testing errors!');
// should output red console error:
// MyAwesomeComponentApp - Error: testing errors!