Coder Social home page Coder Social logo

Comments (9)

RanzQ avatar RanzQ commented on May 31, 2024

@jduprey This is a limitation with the default ConsoleFormattedStream. Browser outputs the line where console.log is called, but the real info is in rec.src. You can create your own stream (check what ConsoleFormattedStream does). Since this is not the full node-bunyan, some things might not work as expected. :)

from browser-bunyan.

RanzQ avatar RanzQ commented on May 31, 2024

Actually after trying this myself, the rec.src is empty, due to this line being commented:

https://github.com/philmander/browser-bunyan/blob/master/lib/bunyan.js#L98

Anyway, how I modified the stream:

 function getSourceLine (rec) {
      console.log('getting src', JSON.stringify(rec.src))
      if (!rec.src) return ''
      else return ' [' + rec.src.file + ':' + rec.src.line + ']'
    }

    console.log('[%s:%s:%s:%s]%s %c%s%c: %s: %c%s',
        padZeros(rec.time.getHours(), 2), padZeros(rec.time.getMinutes(), 2),
        padZeros(rec.time.getSeconds(), 2), padZeros(rec.time.getMilliseconds(), 4),
        getSourceLine(rec),
        levelCss, levelName,
        defaultCss, loggerName,
        msgCss, rec.msg);
    if(rec.err && rec.err.stack) {
        console.log('%c%s,', levelCss, rec.err.stack);
    }

from browser-bunyan.

philmander avatar philmander commented on May 31, 2024

Thankyou @RanzQ

I'm looking into this a bit more.

from browser-bunyan.

philmander avatar philmander commented on May 31, 2024

@RanzQ I tried to replicate your fix, but I get an error:

browser-bunyan.js:99 Uncaught TypeError: Object.defineProperty called on non-object

This is also after setting src:true in the logger options. Does it definitely work for you?

This is probably why I commented out that line originally. I'm thinking I might need to do something along these lines:

var err = new Error();
var stack = err.stack;
rec.src = getThirdCallerFromStack(stack) // I think this part would require some x-browser stack trace parsing code

from browser-bunyan.

RanzQ avatar RanzQ commented on May 31, 2024

@philmander Yeah sorry, forgot to update the answer. After uncommenting the line I ended up with the same error. My "fix" was just for the string format.

I can try with original bunyan if it works with webpack.

from browser-bunyan.

RanzQ avatar RanzQ commented on May 31, 2024

So, wasn't able to make it work with the node-bunyan either, I just get an empty object from getCaller3Info.

I've found it best to debug with console.log and create the final logger with browser-bunyan. When using named child loggers you don't necessarily need the line number. :)

from browser-bunyan.

philmander avatar philmander commented on May 31, 2024

I've added line number support on this branch. This contains a working build

I've tested in latest Chrome and Firefox. I will do some testing/add-support in other browsers, probably IE and Safari and then merge and then release

from browser-bunyan.

philmander avatar philmander commented on May 31, 2024

I've released a fix working across major browsers @ 0.3.0

from browser-bunyan.

jduprey avatar jduprey commented on May 31, 2024

Thank you!

from browser-bunyan.

Related Issues (20)

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.