philmander / browser-bunyan Goto Github PK
View Code? Open in Web Editor NEWAn adaptation of, the Node logging library, Bunyan specifically for the browser.
License: Other
An adaptation of, the Node logging library, Bunyan specifically for the browser.
License: Other
Currently, bunyan's req.src
shows the compiled location (an asset bundle), as opposed to the location in the sourcemap.
// ConsoleFormattedStream
... Class.updateCount (http://localhost:4200/assets/project-assets.js:1382:12) bunyan.js:259
// stdout
...
src: "Class.updateCount (http://localhost:4200/assets/project-assets.js:1382:12)"
NB: Asset compilation was performed via Broccoli (ember-cli build pipeline)
log message local-file.js.js:93
NB: Identical behavior between browerified node-bunyan and browser-bunyan
Thank you for this project. I read the docs and it support send the logs to a server endpoint. But I did not find any server implementation details, is there an existing implementation or we need to implement a simple server endpoint to receive the logs manually (it seems not very difficult though).
Thanks,
Shenghong
I noticed that when flushOnClose is on, browser-bunyan's ServerStream seems to be sending out the records with content-type set as text/plain
instead of application/json
.
Is this intentional?
I've been accepting application/json from browser-bunyan and I've been seeing 415 errors because of invalid content-type.
Thanks!
It appears that any messages that are logged before the logApiThrottle (in milliseconds) time has passed are not passed to the network call. When we wait for this amount of time before calling logger.info it will pass this first log to the network request.
i.e
const throttle = 500
const logger = getLogger({
name: 'Client',
logApiUri: "/test",
streams: { isServerStreamEnabled: true },
throttleInterval: throttle,
});
logger.info("testing") // not sent over network
setTimeout(() => logger.info("testing"), throttle) // sent over network
Messages that are sent directly after initialization are not passed to the network call
Hi @philmander,
Thanks for the package, great stuff! ๐
I am using the logger with console-formatted-stream
I would like to have the formatted stream gracefully support objects passed as arguments. Today it prints out [object Object]
.
I think it is pretty simple, multiple arguments could be passed to console.log
instead of using argument substitution.
I have forked the package.
I did this in my fork:
npm install -g lerna
cd browser-bunyan
npm install
lerna bootstrap
lerna publish
npm link
I changed some source code and tried to see if I inspect the code. I seem unable to make a change that gets picked up by my package pointer in the node_modules
file.
lerna
build with microbundle
? I looked at the flags for these tools and nothing stands out.lerna publish
only seems to build the git HEAD
?npm run build
which runs microbundle
directly.If I had a simple guide to forking and debugging I could add the feature that I would like to see and maybe send you a PR.
Thanks!
When I do something like:
log.warn({foo: "bar"}, 'hello')
with ConsoleFormattedStream, the object fields are not shown in the JavaScript console.
I feel like this used to work, but not any more. Maybe they changed something in Chrome.
To reproduce, set up a browser-bunyan logger with ConsoleFormattedStream and try logging an object parameter in the latest version of Chrome, see if it shows the object or not.
This way we can use it for universal javascript applications and choose how we would like to stream it depending on environment
Noticed you included an Angular-specific example in the README.md in 0dd9ee4.
Would you accept a PR for an Ember-specific example?
First draft in Stack Overflow, see: https://stackoverflow.com/a/47423545/3684641
export function myLogger(): void {
const logger = createLogger({
name: 'myLogger',
level: INFO,
stream: new ServerStream({
url: 'http://0.0.0.0:8080/sandbox',
method: 'POST'
}),
});
logger.info("testtest");
}
I have this basic implementation of ServerStream, and I'm trying to write a test to check that ServerStream is actually working.
However, when I run the jest test, I realize that my endpoint never gets hit when the test is running.
However, when I run this function normally, I am able to see that the endpoint is hit
Is this an expected behavior?
hi, right now i am sending logs to a server using server-stream, but i need to add custom headers in the request, is there any way to do that ? here is an example of how i am doing it:
logInstance = createLogger({
name: 'my-landing',
streams: [{
level: INFO,
stream: new ServerStream({
url: ${config.baseURLbff}logs
,
method: 'POST',
}),
}],
})
Hi,
I have added seq (via bunyan-seq) to my bunyan-browser config to send message to a server. However, when the server is not available bunyan-browser throws an error.
I already registered an onError handler to the my stream, but that just shows, a message to the console that an error occured. I would like to remove the stream from my logger to avoid further error, especially failures in my app, due to a not reachable stream.
Is there any way to remove a stream from an existing logger?
When logging objects, the object is output on the line following the formatted text output.
This is pretty much fine when reading through the logs. But when using console filter/find features it is a total pain. Because the object is output on the next line and it is not available in the search results.
It is pretty simple to modify ConsoleFormattedStream
to output the object on the same line.
if (rec.src) {
logArgs.push(srcCss);
logArgs.push(rec.src);
}
+ if (rec.obj) {
+ logArgs.push(rec.obj);
+ }
consoleMethod.apply(console, logArgs);
if (rec.err && rec.err.stack) {
consoleMethod.call(console, '%c%s,', levelCss, rec.err.stack);
}
- if (rec.obj) {
- consoleMethod.call(console, rec.obj);
- }
Hi,
For <script src="//unpkg.com/[email protected]/dist/browser-bunyan.min.js"></script>
, I am able to instantiate bunyan.ConsoleRawStream
and ConsoleRawStream.ConsoleFormattedStream
but not bunyan.ServerStream
. Can we have bunyan.ServerStream
package into browser-bunyan.min.js
?
Thanks
It would be nice if the server-stream
package would also send it's current batch (regardless of if it's full) when the browser is about to close the tab.
This would avoid lost log messages between the last batch sent and when the browser shuts down the tab.
Assuming that I for example want to have auth headers (like Bearer token), these may need to be updated from time to time. If headers could be configured to be provided through a (async) function called on each request to send to the server, that would be a simple solution for the library user.
"var bunyan = require('./lib/bunyan');" as given in the documentation example is NodeJS code, you cannot use that in browser. Hence the provided example of
<...>
$delegate = bunyan.createLogger({
<...>
is extremely unclear - where does the "bunyan" instance come from? When I attempt to inject "bunyan" or "browser-bunyan" into my Angular module, I get "Module 'bunyan' (or "browser-bunyan") is not available!" errors.
Could you please clarify documentation regarding how it's supposed to be done?
Is it possible for ServerStream to send the request body as a single JSON instead of an array of JSON?
export function testLogger(): void {
const logger = createLogger({
name: 'myLogger',
streams: [
{
level: INFO,
stream: new ServerStream({
url: 'http://0.0.0.0:8080/sandbox',
method: 'POST'
}),
}
],
});
logger.info({"test" : "test123"});
}
Output:
[
{
"name":"myLogger",
"level":30,
"test":"test123",
"levelName":"info",
"msg":"",
"time":"2019-03-15T21:07:14.058Z",
"v":1,
"url":"http://0.0.0.0:4321/",
"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
"count":1
}
]
Desired output:
{
"name":"myLogger",
"level":30,
"test":"test123",
"levelName":"info",
"msg":"",
"time":"2019-03-15T21:07:14.058Z",
"v":1,
"url":"http://0.0.0.0:4321/",
"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
"count":1
}
Hi, thanks for your smart browser logger.
I implement simple custom class which call your logger behaviour as below image show.
utils/logger.js
But I notice the error stack output which locate to my class instead of real position.
If I want to reserve error stack from my logic caller (like my app.js) instead of my custom logger.js, how should I implement it?
Thanks for your time,
regards.
Hi! My log is getting quite cluttered. Is there a way to exclude fields?
Like v
, count
, time
?
I read this discussion (trentm/node-bunyan#52) about excluding fields for bunyan
, but I wasn't successful for browser-bunyan
. Some help would be appreciated. Thanks so much.
I have an issue with @browser-bunyan/server-stream
if server return an error, the failed log message never send, but next request doubled
steps to reproduce:
config:
const logger = createLogger({
name: 'serverLogger',
streams: [{
level: WARN,
stream: new ServerStream({
url: '/api/v1/logger',
method: 'POST'
}),
}],
});
Do you have plans to support few more features such timer similar to console.time(label);
?
import { ConsoleRawStream } from 'browser-bunyan'; // compilation error in 1.6.2
It is exported and inlined in the all the JS-file inside the brower-bunyan package, but it's types are not exported it in the TypeScript definition.
This happened when bumping from 1.5.3 to 1.6.2.
The documentation might suggest that I should import from @browser-bunyan/console-raw-stream
instead, but since it's already inlined in browser-bunyan
doesn't that lead to duplicate code in my bundle?
line needs to be either
method.toLowerCase() === 'post'
or
method.toUpperCase() === 'POST'
I want to create SentryStream
and this stream will send fatal errors to sentry.
Sentry has the ability to return issue id
- I want somehow to get this ID.
Could we just return an array of results of executing write
methods?
Like this #67
Will work like this:
export class SentryStream {
write(rec) {
// send error to Sentry
const id = "...." // some Sentry Issue ID
return id;
}
}
const result = logger.fatal(new Error('some error'));
console.log(result); // ["...sentry-issue-id..."]
I'm using browser bunyan and I've configured it to log the source file and line number, but it is reporting file and line in bunyan.
Initialized:
$provide.decorator('$log', function($delegate) {
$delegate = bunyan.createLogger({
name: 'tracer-logger',
src: true,
streams: [{
level: 'info',
stream: new bunyan.ConsoleFormattedStream(),
type: 'raw'
}]
});
return $delegate;
});
Console log:
[20:01:30:0512] INFO: tracer-logger: Websocket batch update [23]. browser-bunyan.min.js:6
https://www.evernote.com/l/AAIdfssu8jtKRJlPsailB1hqB82VVadfzGM
What am I doing wrong?
When creating a child logger a childName
field can be passed and utilized by console-formatted-stream
,
This appears to be undocumented.
I was in the process of creating my own version of console-formatted-stream
when I discovered this.
Hello,
When I try to import { ServerStream } from '@browser-bunyan/server-stream'; , I get an error saying "Error: Cannot find module '@browser-bunyan/server-stream'"
We have a requirement that we'd like to have the logs sent back to the server when a user changes pages. It looks like the library supports dumping the logs when the user closes the tab or window via the unload
event, and we'd like to add in the option to dump them via the beforeunload
event as well.
We are fine to make the change, however we have a lengthy review process we have to go through in order to contribute to open source projects. So before we go through that process we'd like to verify that A) this isn't already being worked on and B) this is a change that would be a welcome addition to the library.
Do the types link still valid for v1.3.0
?
Hello, have a standard setup with one stream, however objects are not Pretty-printed.
Is there a setup item required, or should this be standard output, on the console.
Bob
Any suggestion for how to rebase this on top of bunyan master? I thought there's would be a fork reference between the github repos but that does not appear to be the case.
Hey @philmander,
Looks like there has been additional divergence and bug fixes between bunyan and browser-bunyan since #4 last year.
Are there any plans to bring in changes from bunyan? Wondering if this npm module is maintained/safe to use, or whether I should just accept a bit of bloat from a browersfied bunyan and excerpt (failed because of divergence between browersfied bunyan and browser-bunyan).ConsoleFormattedStream
from brower-bunyan
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.