philmander / browser-bunyan

An adaptation of, the Node logging library, Bunyan specifically for the browser.
Other
93 stars 21 forks source link

no contributors guide #22

Closed brucejo75 closed 6 years ago

brucejo75 commented 6 years ago

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.

Forked

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

Tried to modify

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.

Confused

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!

philmander commented 6 years ago

Hi Bruce - sorry to hear things aren't totally clear. I will look into a contributing guide asap, with your specific case in mind.

philmander commented 6 years ago

I added a quick CONTRIBUTING doc and here are some more specific answers:

How can I make a simple change that I can check out? I do not think simple npm link is working for me.

Say you made a change to packages/console-formatted-stream

npm run bootstrap
cd packages/console-formatted-stream
npm link

cd /path/to/project
npm link @browser-bunyan/console-formatted-stream

How can I construct a debug build? All the code is minimized by the lerna build with microbundle? I looked at the flags for these tools and nothing stands out.

Could you be more specific about what you would like a debug build to entail? Microbundle does build with source maps. You can also turn off minifying with --compress false

I also add some tests to console-formatted-stream, to help you, which were absent before. Writing a test. then, should be your first step for writing a new feature - instead of building and linking to an external page (you should only want to do that as a sanity test).

Finally, you can also test the UMD build of packages/browser-bunyan which will pull in packages/console-formatted-stream (after bootstrapping with Lerna) by opening ./examples/index.html in a browser.

lerna publish only seems to build the git HEAD? I made modifications in the package and then ran npm run build which runs microbundle directly.

Not sure what you mean here. lerna publish will attempt to publish any new commits to NPM. This is intended and is not part of the normal development workflow. I currently run this manually to publish a new version.

philmander commented 6 years ago

Regarding the thing you're actually trying to do. Is this not sufficient:?

logger.info({ obj: myObject }, 'I just logged my object');

This is how the stream is currently designed to deal with logging objects.

brucejo75 commented 6 years ago

Hi @philmander,

Thanks for the quick response. BTW: I really do not understand lerna or microbundle at all, so wandering in the dark a bit.

Using { obj: myObject } gets me over the hump for most of my cases.

I am seeing other issues that I want to explore a bit. They may be real issues or a misunderstanding of the tool on my part, stepping through code helps me to understand which 😃. (this helps to keep me from spamming project owners with non-issues)

What I am working on now: I cannot get log.trace to work. I level: TRACE in createLogger but log.trace is skipped. Stepping through the code will help me to identify my issue or browser-bunyan issue.

Why am I wanting to build a non-minified version?

npm link console-formatted-stream

I tried npm link for console-formatted-stream and it seems to create the link properly.

npm link browser-bunyan

Should I expect this to work?

I could not get it to work for browser-bunyan, when I npm link -or- npm install in that directory I get:

npm ERR! code ETARGET
npm ERR! notarget No matching version found for @browser-bunyan/console-plain-stream@1.3.0
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/bruce/.npm/_logs/2018-10-23T04_20_04_393Z-debug.log

Which is odd because console-plain-stream is set to v1.4.0 in both the browser-bunyan dependency and for the package version of @browser-bunyan/console-plain-stream, I also checked the manifest in NPM and the latest is set to 1.4.0. Where is 1.3.0 coming from?

Here is the output of 2018-10-23T04_20_04_393Z-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ '/home/bruce/.nvm/versions/node/v8.11.1/bin/node',
1 verbose cli   '/home/bruce/.nvm/versions/node/v8.11.1/bin/npm',
1 verbose cli   'install' ]
2 info using npm@5.10.0
3 info using node@v8.11.1
4 verbose npm-session 002f277e3861a3f8
5 silly install runPreinstallTopLevelLifecycles
6 silly preinstall browser-bunyan@1.4.0
7 info lifecycle browser-bunyan@1.4.0~preinstall: browser-bunyan@1.4.0
8 silly install loadCurrentTree
9 silly install readLocalPackageData
10 timing stage:loadCurrentTree Completed in 43ms
11 silly install loadIdealTree
12 silly install cloneCurrentTreeToIdealTree
13 timing stage:loadIdealTree:cloneCurrentTree Completed in 1ms
14 silly install loadShrinkwrap
15 http fetch GET 304 http://registry.npmjs.org/@browser-bunyan%2fconsole-plain-stream 247ms (from cache)
16 silly registry:manifest no matching version for @browser-bunyan/console-plain-stream@1.3.0 in the cache. Forcing revalidation
17 http fetch GET 304 http://registry.npmjs.org/@browser-bunyan%2fconsole-plain-stream 119ms (from cache)
18 silly fetchPackageMetaData error for @browser-bunyan/console-plain-stream@1.3.0 No matching version found for @browser-bunyan/console-plain-stream@1.3.0
19 timing stage:rollbackFailedOptional Completed in 0ms
20 timing stage:runTopLevelLifecycles Completed in 708ms
21 silly saveTree browser-bunyan@1.4.0
21 silly saveTree └─┬ @browser-bunyan/console-formatted-stream@1.3.0
21 silly saveTree   └── @browser-bunyan/levels@1.3.0
22 verbose type version
23 verbose stack @browser-bunyan/console-plain-stream: No matching version found for @browser-bunyan/console-plain-stream@1.3.0
23 verbose stack     at pickManifest (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/node_modules/npm-pick-manifest/index.js:65:11)
23 verbose stack     at fetchPackument.then.packument (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:52:18)
23 verbose stack     at fetchPackument.then.packument (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:51:58)
23 verbose stack     at runCallback (timers.js:794:20)
23 verbose stack     at tryOnImmediate (timers.js:752:5)
23 verbose stack     at processImmediate [as _immediateCallback] (timers.js:729:5)
23 verbose stack     at getManifest (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:37:52)
23 verbose stack     at manifest (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:24:10)
23 verbose stack     at Object.manifest (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/index.js:12:12)
23 verbose stack     at Object.Fetcher#manifest [as manifest] (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/node_modules/protoduck/node_modules/genfun/lib/genfun.js:15:38)
23 verbose stack     at manifest (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetch.js:16:18)
23 verbose stack     at pinflight (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/manifest.js:24:12)
23 verbose stack     at /home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:29:24
23 verbose stack     at _inflight (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:28:25)
23 verbose stack     at /home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:22:14

Thanks!

philmander commented 6 years ago

Lerna is a tool for helping to manage multiple npm packages in a single git repository. I split Browser Bunyan in to multiple packages so I could add optional packages like server-stream without bloating the core build. (Although it does complicate things a little)

Can you tell me exactly how you including Browser Bunyan in your project. There are several ways. Then I can tell you exactly how to create a minified build.

Concerning the log level issue can you share some code? This part is quite well tested so it's doubtful that it's a bug.

On Tue, Oct 23, 2018, 07:31 Bruce Johnson notifications@github.com wrote:

Hi @philmander https://github.com/philmander,

Thanks for the quick response. BTW: I really do not understand lerna or microbundle at all, so wandering in the dark a bit.

Using { obj: myObject } gets me over the hump for most of my cases.

I am seeing other issues that I want to explore a bit. They may be real issues or a misunderstanding of the tool on my part, stepping through code helps me to understand which 😃. (this helps to keep me from spamming project owners with non-issues)

What I am working on now: I cannot get log.trace to work. I level: TRACE in createLogger but log.trace is skipped. Stepping through the code will help me to identify my issue or browser-bunyan issue. Why am I wanting to build a non-minified version?

  • I am working on a Windows box using WSL (Ubuntu). I run node from Ubuntu.
  • My chrome debugger is Windows Native
  • Unfortunately, Chrome devTools do not handle my file paths.
    • All my node paths are Ubuntu
    • Windows Chrome devTools only understands windows paths
  • in devTools network paths to the files work reliably bottom line: source maps don't work either, so being able to rebuild without minifying is super helpful.

npm link console-formatted-stream

I tried npm link for console-formatted-stream and it seems to create the link properly. npm link browser-bunyan

Should I expect this to work?

I could not get it to work for browser-bunyan, when I npm link -or- npm install in that directory I get:

npm ERR! code ETARGET npm ERR! notarget No matching version found for @browser-bunyan/console-plain-stream@1.3.0 npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in: npm ERR! /home/bruce/.npm/_logs/2018-10-23T04_20_04_393Z-debug.log

Which is odd because console-plain-stream is set to v1.4.0 in both the browser-bunyan dependency and for the package version of @browser-bunyan/console-plain-stream, I also checked the manifest in NPM and the latest is set to 1.4.0. Where is 1.3.0 coming from?

Here is the output of 2018-10-23T04_20_04_393Z-debug.log:

0 info it worked if it ends with ok 1 verbose cli [ '/home/bruce/.nvm/versions/node/v8.11.1/bin/node', 1 verbose cli '/home/bruce/.nvm/versions/node/v8.11.1/bin/npm', 1 verbose cli 'install' ] 2 info using npm@5.10.0 3 info using node@v8.11.1 4 verbose npm-session 002f277e3861a3f8 5 silly install runPreinstallTopLevelLifecycles 6 silly preinstall browser-bunyan@1.4.0 7 info lifecycle browser-bunyan@1.4.0~preinstall: browser-bunyan@1.4.0 8 silly install loadCurrentTree 9 silly install readLocalPackageData 10 timing stage:loadCurrentTree Completed in 43ms 11 silly install loadIdealTree 12 silly install cloneCurrentTreeToIdealTree 13 timing stage:loadIdealTree:cloneCurrentTree Completed in 1ms 14 silly install loadShrinkwrap 15 http fetch GET 304 http://registry.npmjs.org/@browser-bunyan%2fconsole-plain-stream 247ms (from cache) 16 silly registry:manifest no matching version for @browser-bunyan/console-plain-stream@1.3.0 in the cache. Forcing revalidation 17 http fetch GET 304 http://registry.npmjs.org/@browser-bunyan%2fconsole-plain-stream 119ms (from cache) 18 silly fetchPackageMetaData error for @browser-bunyan/console-plain-stream@1.3.0 No matching version found for @browser-bunyan/console-plain-stream@1.3.0 19 timing stage:rollbackFailedOptional Completed in 0ms 20 timing stage:runTopLevelLifecycles Completed in 708ms 21 silly saveTree browser-bunyan@1.4.0 21 silly saveTree └─┬ @browser-bunyan/console-formatted-stream@1.3.0 21 silly saveTree └── @browser-bunyan/levels@1.3.0 22 verbose type version 23 verbose stack @browser-bunyan/console-plain-stream: No matching version found for @browser-bunyan/console-plain-stream@1.3.0 23 verbose stack at pickManifest (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/node_modules/npm-pick-manifest/index.js:65:11) 23 verbose stack at fetchPackument.then.packument (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:52:18) 23 verbose stack at fetchPackument.then.packument (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:51:58) 23 verbose stack at runCallback (timers.js:794:20) 23 verbose stack at tryOnImmediate (timers.js:752:5) 23 verbose stack at processImmediate [as _immediateCallback] (timers.js:729:5) 23 verbose stack at getManifest (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:37:52) 23 verbose stack at manifest (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:24:10) 23 verbose stack at Object.manifest (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/index.js:12:12) 23 verbose stack at Object.Fetcher#manifest [as manifest] (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/node_modules/protoduck/node_modules/genfun/lib/genfun.js:15:38) 23 verbose stack at manifest (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/lib/fetch.js:16:18) 23 verbose stack at pinflight (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/pacote/manifest.js:24:12) 23 verbose stack at /home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:29:24 23 verbose stack at _inflight (/home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:28:25) 23 verbose stack at /home/bruce/.nvm/versions/node/v8.11.1/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:22:14

Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/philmander/browser-bunyan/issues/22#issuecomment-432098315, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJLuU-1SRCUNCvfzKXk1Hk87Oujhr5Xks5unqmwgaJpZM4XyqiM .

brucejo75 commented 6 years ago

This part is quite well tested so it's doubtful that it's a bug.

That was my expectation, that is why I wanted to step through it.

Install: npm install browser-bunyan

code:

  import { createLogger, TRACE, INFO, stdSerializers} from 'browser-bunyan';
  import { ConsoleFormattedStream } from '@browser-bunyan/console-formatted-stream';

  let log = createLogger({
    'name': 'Meris',
    streams: [
      {
          level: INFO, // or use the string 'info'
          stream: new ConsoleFormattedStream({'logByLevel': true})
      }
    ],
    serializers: stdSerializers,
    src: true
  });
  log.info(`Browser Bunyan logging started: level: ${log._level}`);
  log.trace(`TRACING: Browser Bunyan logging started: level: ${log._level}`);

ps: how do you set up the ... thing?

philmander commented 6 years ago

In your example, you'll only see trace (and debug) log ouput if your logging level is set to TRACE:

streams: [
      {
          level: TRACE, // or use the string 'info'
          stream: new ConsoleFormattedStream({'logByLevel': true})
      }
    ],

In your code, you do import TRACE, but you don't actually use it.

brucejo75 commented 6 years ago

Sorry, late last night...

I was trying different settings and I had left it at INFO. When I set it to TRACE, log.trace still does not output and neither does log.debug.

I also tried setting it to DEBUG and they still do not output.

Is there a way that npm link will work with packages/browser-bunyan? I figured out how to build a non-minified version.

philmander commented 6 years ago

I realized what is going on. If you're using the logByLevel option, ConsoleFormattedStream will log to the console using console.debug for the debug and trace levels.

By default, Chrome's console does not display these messages unless its log level is set to "verbose". Look for the dropdown at the top of the console with the value set to "Default levels". Then setting the log level to TRACE or DEBUG should work.

This is actually all by design, although a note in the README about this when using the logByLevel is probably worthwhile.

philmander commented 6 years ago

You should link the main package, the same way I recommended for console-formatted-stream:

cd packages/browser-bunyan
npm link

cd /path/to/project
npm link browser-bunyan

n.b. for backwards compatibility the core browser bunyan package is not scoped with @browser-bunyan/ like the other packages

brucejo75 commented 6 years ago

Thanks @philmander, setting the level in the console works. That would have taken me a while to figure out 😕!

when I npm link in packages/browser-bunyan I get the error described in this comment.

Which is a totally confusing error.

brucejo75 commented 6 years ago

I removed package-lock.json, that did the trick.

philmander commented 6 years ago

I was just about to ask you to try that!

philmander commented 6 years ago

The package-lock.json is now removed on the master branch