Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to skip stack frame in src? #423

Open
SomeoneWeird opened this issue Jul 11, 2016 · 2 comments
Open

Possible to skip stack frame in src? #423

SomeoneWeird opened this issue Jul 11, 2016 · 2 comments

Comments

@SomeoneWeird
Copy link

We have a library we use to massage messages into a format our logs use, lets call it logMe

Something like:

function logMe(data1, data2) {
  bunyan.info(data2, data1)
}

(Obviously a little more complicated than this, but yeah)

This works fine, but screws up the src param when it's enabled, it always points to the line where logMe is defined.

What do you think about being able to pass in a skipSrc param (or named something else, naming is hard) that skips n frames at the top of the list when processing the current stack trace?

@joelpurra
Copy link

Your milage may vary, but instead of wrapping in a function, I just re-used the pointer to bunyan's logging methods. This way there is no extra frame.

Here's an example. (Obviously a little more complicated than this, but yeah.)

export default class CustomLogger {
    constructor() {
        this._bunyanLogger = bunyan.createLogger(...);

        const levels = [
            'fatal',
            'error',
            'warn',
            'info',
            'debug',
            'trace',
        ];

        levels.forEach((level) => {
            this[level] = this._bunyanLogger[level].bind(this._bunyanLogger);
        });
    }
}

You can also .bind() extra variables if you'd like; this._bunyanLogger[level].bind(this._bunyanLogger, 'My custom logging prefix.'), but then you might also want to look at bunyan's child loggers.

@trentm
Copy link
Owner

trentm commented Apr 13, 2017

Sorry for the stupid delay. This would depend on #460 work (currently high on my list). Sounds like a good feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants