Roc provides a utility for extensions that can be used to log things to the console, keeping output consistent across all the different packages and plugins.
There is two ways to use the logging function from Roc. Either by using the function that is provided on the main export, as seen here or by importing it directly as below.
import initSmall from 'roc/log/small';
import initLarge from 'roc/log/large';
import initLog from 'roc/log';
import smallDefault from 'roc/log/default/small';
import largeDefault from 'roc/log/default/large';
import initLogDefault from 'roc/log/default';
Used for large messages.
When having a logger each of the types can be used as a property. The logging function takes in a message as the first argument. The second and the third arguments are optional and can be in any order. An optional Error
and a label text as a string. If verbose
is enabled the error.stack
will be displayed, otherwise just error.message
.
Example
import initLarge from 'roc/log/large';
const log = initLarge(packageJSON.name, packageJSON.version);
log.error('Some message', 'Label Text Override', potentialError);
Output: console.info
Color: cyan
Label: Info
Output: console.warn
Color: yellow
Label: Warning
Output: console.error
Color: red
Label: Error
Output: console.log
Color: green
Label: Success
Used to specify a logger function on console
. First argument should be a string that can be either info
, warn
, error
or log
. The second argument is is the default label text.
log.raw('info', 'Information')('a message', potentialError);
Used for small messages.
Several modes exists that can be used.
When having a logger each of the types can be used as a property. The logging function takes in a message as the first argument and the second and third arguments can be in any order. An optional Error
and a boolean that determines if a potential symbol should be shown, default to true
. If verbose
is enabled the error.stack
will be displayed, otherwise just error.message
.
Example
import initSmall from 'roc/log/small';
const log = initSmall(packageJSON.name, packageJSON.version);
log.error('Some message', potentialError, showSymbol);
Output: console.log
Color: Default
Output: console.info
Color: cyan
Symbol: ℹ
Output: console.warn
Color: yellow
Symbol: ⚠
Output: console.error
Color: red
Symbol: ✖
Output: console.log
Color: green
Symbol: ✔
Used to specify a logger function on console
. First argument should be a string that can be either info
, warn
, error
or log
. The second argument is an optional color from chalk
. The third argument is an optional symbol to show in front of the message.
log.raw('info', 'blue', '🦄')('a message', potentialError, showSymbol);