trentm / node-bunyan

a simple and fast JSON logging module for node.js services
Other
7.18k stars 516 forks source link

Electron support #481

Open ghost opened 7 years ago

ghost commented 7 years ago

I'm building an electron (v1.4.15) app with webpack and want to use bunyan for logging. After adding the proper aliases I run into a error TypeError: dtrace.createDTraceProvider is not a function. If I block out dtrace-provider in my webpack config, everything goes according to plan but webpack throws the can't resolve warning:

WARNING in ./packages/mrtl-desktop/~/bunyan/lib/bunyan.js
Module not found: Error: Can't resolve 'dtrace-provider' in 'C:\..\mrtl-desktop\node_modules\bunyan\lib'
 @ ./packages/mrtl-desktop/~/bunyan/lib/bunyan.js 79:17-48

I've resorted to adding new IgnorePlugin(/dtrace-provider/) in my config which resolves the error, but I'm not sure if this is the best solution........

RXminuS commented 7 years ago

Running into a maybe related issue?. However even disabling in config doesn't seem to solve it for me. :-/ Electron 1.6.0

Error: The module '<omitted>/node_modules/dtrace-provider/build/Release/DTraceProviderBindings.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 48. This version of Node.js requires
NODE_MODULE_VERSION 53. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or`npm install`).
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at <omitted>/node_modules/dtrace-provider/dtrace-provider.js:17:23
    at Object.<anonymous> (<omitted>/node_modules/dtrace-provider/dtrace-provider.js:42:2)
{ Error: Cannot find module './build/default/DTraceProviderBindings'
    at Module._resolveFilename (module.js:470:15)
    at Function.Module._resolveFilename (<omitted>/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/common/re
set-search-paths.js:35:12)
trentm commented 7 years ago

I've never played with Electron, so I'm not sure what mechanisms are there that would be appropriate. Help from others appreciated.

If it helps: The dtrace-provider module is an optional part of bunyan. It'll behave just fine without it. It'll just mean that you can't use dtrace and bunyan -p ... to inspect logging of the app at runtime (on platforms that support dtrace -- smartos/illumos/solaris, bsd, and Mac to a degree).

justechn commented 7 years ago

npm install --no-optional gets rid of the error

sumitkm commented 6 years ago

Just to elaborate on @justechn If you have bunyan installed already, uninstall it from your project

npm uninstall bunyan --save

Then install it with the no-optional flag.

npm install bunyan --save --no-optional

I tried to compile the dtrace module only, for electron using electron's provided steps, but it complains about missing gyp config file. @trentm unless you are in a position to fix the dtrace 'node-gyp' config issue, I would close this with the solution being install without dtrace (and ofcourse thanks for bunyan 💯 ).

Here is the error I get when following Electron's suggested steps

I am not familiar enough with the node-gyp/electron-gyp tool-chain to help any further :(

$ HOME=~/.electron-gyp node-gyp rebuild --target=1.7.9 --arch=x64 --dist-url=https://atom.io/download/electron
gyp info it worked if it ends with ok
gyp info using node-gyp@3.6.2
gyp info using node@8.9.3 | darwin | x64
gyp info spawn /usr/bin/python
gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/username/myprojects/github/repo-org/cloud-nine/app/node_modules/dtrace-provider/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/username/.electron-gyp/.node-gyp/iojs-1.7.9/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/username/.electron-gyp/.node-gyp/iojs-1.7.9',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/username/.electron-gyp/.node-gyp/iojs-1.7.9/<(target_arch)/iojs.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/username/myprojects/github/repo-org/cloud-nine/app/node_modules/dtrace-provider',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp: binding.gyp not found (cwd: /Users/username/myprojects/github/repo-org/cloud-nine/app/node_modules/dtrace-provider) while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/node-gyp/lib/configure.js:336:16)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Darwin 17.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/bin/node-gyp" "rebuild" "--target=1.7.9" "--arch=x64" "--dist-url=https://atom.io/download/electron"
gyp ERR! cwd /Users/username/myprojects/github/repo-org/cloud-nine/app/node_modules/dtrace-provider
gyp ERR! node -v v8.9.3
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok