
The Logger class provides an isomorphic and consistent way to log messages to the console.
warn on non-production environments and error on production environments.on on non-test environments and off on test environments.-> symbol.verbose, debug, info, warn or error.true if the status of the logger is ‘off’, false otherwise.true if the status of the logger is ‘on’, false otherwise.The verbose, debug, info, warn, and error methods can be used to log messages to the console.
import { Logger } from '@aracna/core';
const logger = new Logger('logger');
// will log "warn" as a warning
logger.warn('warn');
// will log "error" as an error
logger.error('error');The setLevel method is used to set the level of the logger.
import { Logger } from '@aracna/core';
const logger = new Logger('logger');
logger.setLevel('verbose');
// will log "verbose" as a verbose log
logger.verbose('verbose log');The disable and enable methods are used to disable or enable the logger.
import { Logger } from '@aracna/core';
const logger = new Logger('logger');
logger.disable();
// will not log
logger.warn('warn log');
logger.enable();
// will log
logger.warn('warn log');The disableColors and enableColors methods are used to disable or enable the ANSI colors.
import { Logger } from '@aracna/core';
const logger = new Logger('logger');
logger.enableColors();
// will log "warn" with ANSI colors
logger.warn('warn log');
logger.disableColors();
// will log "warn" without ANSI colors
logger.warn('warn log');The level and status properties of the logger can be set using environment variables.
level property can be set using the formula LOGGER_<NAME>_LEVEL, where <NAME> is the name property of the logger.status property can be set using the formula LOGGER_<NAME>_STATUS, where <NAME> is the name property of the logger.import { Logger } from '@aracna/core';
process.env.LOGGER_APP_LEVEL = 'verbose';
process.env.LOGGER_APP_STATUS = 'on';
const logger = new Logger('APP');
// will log "verbose"
logger.verbose('verbose log');