y-log-io
v0.0.5
Published
console loging to an other terminal. Useful to not disturb the main terminal output.
Downloads
1
Maintainers
Readme
y-log-io
Console loging to an other terminal. Useful to not disturb the main terminal output.
This console outputs to an other terminal to avoid disturbing the layout or primary informations of the main terminal output.
Install :
npm install y-log-io
Exemple 1 : base use.
Script 1 : Get your logger (where you execute you code)
const Log= require('y-log-io');
var logger=Log.getlogger(jsonPath);
logger.log('some',{data:{txt:'abcd',list:[0,1,2]}},['a','b','c']);
Script 2 : show output logs.
const Log= require('y-log-io');
var output = Log.getOutput(theSame_jsonPath);
output.start();
See exemple_01.
Menu
Get logger
Get the logger. This command returns an instance of Input.
/**
get the logger.
@param {string} fileName : path to logs json file OR a registered file alias.
@return {Input} the fake console
*/
YLogIO.getlogger(fileName)
Input
- Properties
- timeout : int default=500.
- Minimal read/write period. The logger wont access the json file more than once evry timeout ms.
- Decrease if you want more responsiveness.
- Increase if you want to limit rw charge.
- maxlog : int default=100.
- maximum logs buffer size. Limits json file size when output is not listening.
- Low value reduce file size and r/w time, but you may loose outputs.
- fileName : string read only
- path to the json file name.
Get Output
Get the logger output. This command returns an instance of Output.
/**
get logger output.
@param {string} fileName : path to logs json file OR a registered file alias.
@return {YL.Output} the console output logger. call logger.start(); to activate.
*/
YLogIO.getOutput(fileName)
Output
- Methods
- .start : Starts the console output.
/**
activate the console.
*/
Output.start();
- Properties
timeout : int default=2000.
- maximal r/w period (fs.watch leaks fix) forced access to json file if no changes have been detected after timeout ms.
splitTimeout : int default=2000.
- display a different log separator when time between log is greater than splitTimeout ms.
startMsg : string
- The message displayed when the output starts.
stackMax : int default=5.
- displayed stack pile maximum size.
show : object
- .startLine : boolean default=true
- Shows startMsg.
- .topLine : boolean default=true
- Shows log separator.
- .info : boolean default=true
- Shows log infos (time method file line).
- .time : boolean default=true
- Shows log time.
- .method : boolean default=true
- Shows log local method.
- .file : boolean default=true
- Shows log current file name.
- .line : boolean default=true
- Shows log current file line number.
- .stack : boolean default=true
- Shows stack pile.
- .startLine : boolean default=true
Aliases
Share the same output among files without caring about different pathes by registering an alias.
/**
register an alias name for the logs json file. useful for access in different file pathes.
@param {string} name : alias of the registered file path.
@param {string} fileName : path to logs json file.
*/
YLogIO.register(name,fileName)
The registration could be done only (but at least) once. Event in a one-shot separated script.
const Log= require('y-log-io');
Log.register('my-alias',pathToAJsonFile);
You can now call logger and output by their alias.
ex logger:
const logger= require('y-log-io').getlogger('my-alias');
ex output :
require('y-log-io').getOutput('my-alias').start();