Git Product home page Git Product logo

jstracer's Introduction

nodejs tracer handle

tracer for multiple handles for use

Release History

  • Apr 1st 2019 Release 1.2.0 to fixup the console.error on get_stacks on Array.forEach nothing
  • Nov 28th 2017 Release 1.1.2 to fixup bug when call the output format of line and files
import * as jstracer from '../../lib';

const trace_exit = function(ec) {
    jstracer.finish(err => {
        if (err) {
            return;
        }
        process.exit(ec);
    });
};

process.on('uncaughtException', err => {
    'use struct';

    jstracer.error('error (%s) stack(%s)', err, err.stack);
    trace_exit(3);
});

process.on('SIGINT', () => {
    trace_exit(0);
});

const args = {
    verbose: 1,
    log_files: [],
    log_appends: [],
    log_console: true,
    log_format: '<{{title}}> {{message}}\n',
};

const value = 'code';
const lvalue = 32;

jstracer.set_args(args);

jstracer.error('value %s lvalue %s', value, lvalue);
jstracer.warn('value %s lvalue %s', value, lvalue);
jstracer.info('value %s lvalue %s', value, lvalue);
jstracer.debug('value %s lvalue %s', value, lvalue);
jstracer.trace('value %s lvalue %s', value, lvalue);

output

<error> [Z:\\jstracer\\libexample\\console\\console2.js:Object.<anonymous>:42] value code lvalue 32
<warn> [Z:\\jstracer\\libexample\\console\\console2.js:Object.<anonymous>:43] value code lvalue 32

to get the special case for special name

import * as jstracer from '../../lib';
import * as extargsparse from 'extargsparse';

const commandline = `{
  "logname|n" : null,
  "$" : "+"
}`;

const trace_exit = function(ec) {
    jstracer.finish(err => {
        if (err) {
            return;
        }
        process.exit(ec);
    });
};

process.on('uncaughtException', err => {
    'use struct';

    jstracer.error('error (%s) stack(%s)', err, err.stack);
    trace_exit(3);
});

process.on('SIGINT', () => {
    trace_exit(0);
});

let parser = extargsparse.ExtArgsParse({
    help_func(ec, s) {
        let fp;
        if (ec === 0) {
            fp = process.stdout;
        } else {
            fp = process.stderr;
        }
        fp.write(s);
        trace_exit(ec);
    },
});
parser.load_command_line_string(commandline);
parser = jstracer.init_args(parser);
const args = parser.parse_command_line();

const logger = jstracer.set_args(args,args.logname);
args.args.forEach(l => {
    logger.error('%s', l);
    logger.warn('%s', l);
    logger.info('%s', l);
    logger.debug('%s', l);
    logger.trace('%s', l);
});

shell call

node example2.js  -n logger1 -vvvv "hello world"

output

<error> [Z:\\jstracer\\libexample\\console\\logname.js::53] hello world
<warn> [Z:\\jstracer\\libexample\\console\\logname.js::54] hello world
<info> [Z:\\jstracer\\libexample\\console\\logname.js::55] hello world
<debug> [Z:\\jstracer\\libexample\\console\\logname.js::56] hello world
<trace> [Z:\\jstracer\\libexample\\console\\logname.js::57] hello world

reference for the key of args set

  • verbose is the verbose mode default 0 for just error output 1 for warn output 2 for info output 3 for debug output 4 for trace output
  • log_files to log into the file default none ,not to the file
  • log_appends : almost as log_files ,but append log to the end of the file
  • log_console : default true for stderr if false ,no logout to stdout
  • log_format : default '<{{title}}> {{message}}\n' will give the vivid

jstracer's People

Contributors

jeppeter avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.