Default console.log
, console.error
, etc. are overridden by this module to stay with familiar functions (only when configuring with default functions names - without params or one as {Options}
)
npm install --save console2file
or (preferred)
yarn add console2file
var c2f = require('console2file').default;
// or
import c2f from 'console2file';
c2f({
fileOnly: false,
labels: true
}); // Overrides default console loggers (and debug)
c2f('rage', {
labels: true
}); // Creates new function with default options
console.info('Hurray!'); // logs '[INFO] Hurray!' to file ./stdout.log and console
console.rage('quit'); // logs '[RAGE] quit' only to file ./stdout.log
or
var c2f = require('console2file');
// or
import {c2f} from 'console2file';
c2f.config({
fileOnly: false,
labels: true
}); // Overrides default console loggers (and debug)
c2f.config('rage', {
labels: true
}); // Creates new function with default options
console.info('Hurray!'); // logs '[INFO] Hurray!' to file ./stdout.log and console
console.rage('quit'); // logs '[RAGE] quit' only to file ./stdout.log
Parameter | Default value | Type | Description |
---|---|---|---|
filePath | './stdout.log' |
string |
File path to log your console (set empty string or not string to disable) |
fileOnly | true |
boolean |
Log only to file or both (file and console) |
labels | false |
boolean |
Display labels (i.e. [LOG] , [ERROR] , ...) |
timestamp | false |
boolean or string |
Display timestamp (i.e. [2018-3-16 00:42:29] ). Format is from moment.js |
interpreter | util.inspect |
function |
Interpretation of non string values (allows to log full objects not as [Object object] etc.) |
MIT