Core Modules
Core modules are optional and can be replaced by any module as long as it provides the same interface.
Some are optional, like the REPL module. If you don't need or don't want a REPL you can remove it from the list of coremodules
using the configuration object that you pass to the application instance during the initialization of your program, in the entry point file.
The most likely scenario is that you might want to enable it during development but not on production.
This is the list of core modules bundled with core.io:
- Logger
- Errors
- Monitoring
- Dispatcher
- REPL
Core modules are loaded first and made available for all user modules. You can override this list using a coremodules
key in the configuration object you initialize your instance with:
const config = Application.loadConfig({
coremodules: ['./logger', './errors', './dispatcher']
}, true);
const app = new Application({config});
Here we removed the monitoring and the REPL.
Dispatcher
REPL
Applications start a repl instance which exposes the context in the app
variable.
════════════════════════════════════════════════════════════════════╗
║ ║
║ poke-repl remote console √ ║
║ ║
║ All connections are monitored and recorded ║
║ Disconnect IMMEDIATELY if you are not an authorized user ║
╚════════════════════════════════════════════════════════════════════╝
REPL Session Information
Name : application-core
Version : 0.0.0
Environment : development
App Kernel > app.getUid()
'jxo6adbd-ts7wnaivr0e'
Logger
core.io provides a logger to the application context as context.logger
and is the module with the highest priority, meaning it will be available on first run. Under the hood the logger wraps [winston][winston] and extends it with some extra features:
- child loggers
- filters
- the ability to mute all output
- the ability to have focus on child logger
- it can optionally wrap the console so that it has the same format
- it can disable
console
output
When a module is loaded a child logger is created and assigned to the module. You access child loggers via the context.logger.getLogger(loggerId)
method, where loggerId
is the name of the logger.
Each call to getLogger
will return the same instance, and it's output is identified by the logger's name:
INFO [23:28:48] ├── core : Created logger "core"...
INFO [23:28:48] ├── app : Created logger "app"...
INFO [23:28:48] ├── console : Created logger "console"...
WARN [23:28:48] ├── core : Register: we are going to override plugin logger
INFO [23:28:48] ├── core : Mount Handler: module "errors" mounted...
INFO [23:28:48] ├── core : Mount Handler: module "dispatcher" mounted...
INFO [23:28:48] ├── dispatcher : Created logger "dispatcher"...
DEBUG [23:28:48] ├── dispatcher : Module "dispatcher" ready...
Each application has at least two loggers; core and app. Using the built in logger is optional, however if you decide to log from within your modules it's a good idea to use the same provided logger.
TIP: When you are initializing your modules, in the init
function, you can access the logger using the context.getLogger
You can wrap the console
so it has the same output as the regular logger output and also you can apply filters.
You can have an active logger, so that only the log output of a given logger is shown.
You can mute all output.
Options:
- muteConsole: Uses [noop-console][noop-console] module.
- wrapConsole
- handlingExceptions
You can set these values by default using the ./config/logger.js
configuration file or you can interact with the logger through the REPL.
Configuration
The default configuration for the logger includes three different transports:
- Console: log level silly.
- File Exceptions: catch and log uncaughtException events
- File Debug: Log level debug. Disabled by default in production.
To override the default configuration you can create a ./config/logger.js
configuration file.