1.0.2 • Published 4 years ago
@alu0100987522/add-logging v1.0.2
AddLogging
This library will add logs after entering a function.
Installation
Install locally in project
~ npm i -D @alu0100987522/add-logging
Install globally
~ npm i -g @alu0100987522/add-logging
Usage
Commands
add-logging
Use this command as a executable for the addLogging module.
~ add-logging
Usage: add-logging [options] <input_filename> Add a console.log after entering a function. Options: -V, --version output the version number -o, --output <filename> stablish an output file to save the final code -p, --pattern <stringPattern> stablish a string pattern to match with names of declared-type functions -h, --help display help for command
add-logging -h --help
Show the version of the library
~ add-logging -h
Usage: add-logging [options] <input_filename> Add a console.log after entering a function. Options: -V, --version output the version number -o, --output <filename> stablish an output file to save the final code -p, --pattern <stringPattern> stablish a string pattern to match with names of declared-type functions -h, --help display help for command
add-logging -V --version
Show the version of the library.
~ add-logging -V 0.1.0
~ add-logging --version 0.1.0
add-logging -o --output
Add a log after entering a function, and write the result in a file.
~ add-logging -o output.js input.js input: function suma(a, b) { return a + b; } Salida en fichero output.js
add-logging -p --pattern
Add a log after enterinf a function but only if the --pattern introduced matches with the name of the function.
~ add-logging --pattern suma input-log.js input.js input: function suma(a, b) { return a + b; } Salida en fichero input-log.js
Import to use
const { addLogging } = require('@alu0100987522/add-logging');
Method
This method add new line of log before your code in functions and return a new string.
It receives 2 parameters:
- Code: {string} code to read and find functions to write the new line
- Pattern: {string} word you want to choose, and find only functions match with that word.
const output = addLogging(input, 'suma')
The variable output contain the string with the code with a new line of log.
Example
Code
const { addLogging } = require('@alu0100987522/add-logging');
const sum = `function suma(a, b) {
return a + b;
}`
const output = addLogging(sum, 'suma')
console.log(output)
Output
~ node src/add.js
function suma(a, b) {
console.log(`Entering suma(${ a },${ b }) at line 1`);
return a + b;
}