Comments (9)
@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.
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.
Thankyou @RanzQ
I'm looking into this a bit more.
from browser-bunyan.
@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.
@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.
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.
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.
I've released a fix working across major browsers @ 0.3.0
from browser-bunyan.
Thank you!
from browser-bunyan.
Related Issues (20)
- a condition inside server stream will never get called HOT 1
- Exclude fields HOT 3
- No option for flushOnNavigate HOT 3
- ServerStream outputs an array of JSON HOT 4
- Is jest not running ServerStream? HOT 6
- Double server records
- start and end timer HOT 1
- [ConsoleFormattedStream]: Log objects to the same console line as the log output HOT 1
- Pretty-printed Setup / Definition - Not Working HOT 1
- flushOnClose sends records as text/plain instead of application/json HOT 3
- ConsoleRawStream. Where do I import it from? HOT 2
- @browser-bunyan/levels: Missing type definition for `nameFromLevel` HOT 1
- Add custom headers to ServerStream HOT 3
- Removal of streams HOT 1
- Do you have plans to support react-native?
- Can we return result of executing "write" methods of streams? HOT 1
- is there an server implementation? HOT 1
- Ability to give headers through function and/or promise
- Log API Throttle / Initialization Issue
- Extra log fields are not logged to browser console HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from browser-bunyan.