\n\nField | \nRequired? | \nDefault | \nDescription | \n
\n\nstream | \nYes | \n- | \nA \"Writable Stream\", e.g. a std handle or an open file write stream. | \n
\n\ntype | \nNo | \nn/a | \n`type == 'stream'` is implied if the `stream` field is given. | \n
\n\nlevel | \nNo | \ninfo | \nThe level to which logging to this stream is enabled. If not\nspecified it defaults to \"info\". If specified this can be one of the\nlevel strings (\"trace\", \"debug\", ...) or constants (`bunyan.TRACE`,\n`bunyan.DEBUG`, ...). This serves as a severity threshold for that stream\nso logs of greater severity will also pass through (i.e. If level=\"warn\",\nerror and fatal will also pass through this stream). | \n
\n\nname | \nNo | \n- | \nA name for this stream. This may be useful for usage of `log.level(NAME,\nLEVEL)`. See the [Levels section](#levels) for details. A stream \"name\" isn't\nused for anything else. | \n
\n
\n\n\n## stream type: `file`\n\nA `type === 'file'` stream requires a \"path\" field. Bunyan will open this\nfile for appending. E.g.:\n\n```js\nvar log = bunyan.createLogger({\n name: 'foo',\n streams: [{\n path: '/var/log/foo.log',\n // `type: 'file'` is implied\n }]\n});\n```\n\n\n\nField | \nRequired? | \nDefault | \nDescription | \n
\n\ntype | \nYes | \n- | \n\"rotating-file\" | \n
\n\npath | \nYes | \n- | \nA file path to which to log. Rotated files will be \"$path.0\",\n\"$path.1\", ... | \n
\n\nperiod | \nNo | \n1d | \nThe period at which to rotate. This is a string of the format\n\"$number$scope\" where \"$scope\" is one of \"ms\" (milliseconds -- only useful for\ntesting), \"h\" (hours), \"d\" (days), \"w\" (weeks), \"m\" (months), \"y\" (years). Or\none of the following names can be used \"hourly\" (means 1h), \"daily\" (1d),\n\"weekly\" (1w), \"monthly\" (1m), \"yearly\" (1y). Rotation is done at the start of\nthe scope: top of the hour (h), midnight (d), start of Sunday (w), start of the\n1st of the month (m), start of Jan 1st (y). | \n
\n\ncount | \nNo | \n10 | \nThe number of rotated files to keep. | \n
\n\nlevel | \nNo | \ninfo | \nThe level at which logging to this stream is enabled. If not\nspecified it defaults to \"info\". If specified this can be one of the\nlevel strings (\"trace\", \"debug\", ...) or constants (`bunyan.TRACE`,\n`bunyan.DEBUG`, ...). | \n
\n\nname | \nNo | \n- | \nA name for this stream. This may be useful for usage of `log.level(NAME,\nLEVEL)`. See the [Levels section](#levels) for details. A stream \"name\" isn't\nused for anything else. | \n
\n
\n\n\n**Note on log rotation**: Often you may be using external log rotation utilities\nlike `logrotate` on Linux or `logadm` on SmartOS/Illumos. In those cases, unless\nyour are ensuring \"copy and truncate\" semantics (via `copytruncate` with\nlogrotate or `-c` with logadm) then the fd for your 'file' stream will change.\nYou can tell bunyan to reopen the file stream with code like this in your\napp:\n\n```js\nvar log = bunyan.createLogger(...);\n...\nprocess.on('SIGUSR2', function () {\n log.reopenFileStreams();\n});\n```\n\nwhere you'd configure your log rotation to send SIGUSR2 (or some other signal)\nto your process. Any other mechanism to signal your app to run\n`log.reopenFileStreams()` would work as well.\n\n\n## stream type: `raw`\n\n- `raw`: Similar to a \"stream\" writable stream, except that the write method\n is given raw log record *Object*s instead of a JSON-stringified string.\n This can be useful for hooking on further processing to all Bunyan logging:\n pushing to an external service, a RingBuffer (see below), etc.\n\n\n\n## `raw` + RingBuffer Stream\n\nBunyan comes with a special stream called a RingBuffer which keeps the last N\nrecords in memory and does *not* write the data anywhere else. One common\nstrategy is to log 'info' and higher to a normal log file but log all records\n(including 'trace') to a ringbuffer that you can access via a debugger, or your\nown HTTP interface, or a post-mortem facility like MDB or node-panic.\n\nTo use a RingBuffer:\n\n```js\n/* Create a ring buffer that stores the last 100 records. */\nvar bunyan = require('bunyan');\nvar ringbuffer = new bunyan.RingBuffer({ limit: 100 });\nvar log = bunyan.createLogger({\n name: 'foo',\n streams: [\n {\n level: 'info',\n stream: process.stdout\n },\n {\n level: 'trace',\n type: 'raw', // use 'raw' to get raw log record objects\n stream: ringbuffer\n }\n ]\n});\n\nlog.info('hello world');\nconsole.log(ringbuffer.records);\n```\n\nThis example emits:\n\n```js\n[ { name: 'foo',\n hostname: '912d2b29',\n pid: 50346,\n level: 30,\n msg: 'hello world',\n time: '2012-06-19T21:34:19.906Z',\n v: 0 } ]\n```\n\n## third-party streams\n\nSee the [user-maintained list in the Bunyan\nwiki](https://github.com/trentm/node-bunyan/wiki/Awesome-Bunyan).\n\n\n# Runtime log snooping via DTrace\n\nOn systems that support DTrace (e.g., illumos derivatives like SmartOS and\nOmniOS, FreeBSD, Mac), Bunyan will create a DTrace provider (`bunyan`) that\nmakes available the following probes:\n\n```sh\nlog-trace\nlog-debug\nlog-info\nlog-warn\nlog-error\nlog-fatal\n```\n\nEach of these probes has a single argument: the string that would be\nwritten to the log. Note that when a probe is enabled, it will\nfire whenever the corresponding function is called, even if the level of\nthe log message is less than that of any stream.\n\n\n## DTrace examples\n\nTrace all log messages coming from any Bunyan module on the system.\n(The `-x strsize=4k` is to raise dtrace's default 256 byte buffer size\nbecause log messages are longer than typical dtrace probes.)\n\n```sh\ndtrace -x strsize=4k -qn 'bunyan*:::log-*{printf(\"%d: %s: %s\", pid, probefunc, copyinstr(arg0))}'\n```\n\nTrace all log messages coming from the \"wuzzle\" component:\n\n```sh\ndtrace -x strsize=4k -qn 'bunyan*:::log-*/strstr(this->str = copyinstr(arg0), \"\\\"component\\\":\\\"wuzzle\\\"\") != NULL/{printf(\"%s\", this->str)}'\n```\n\nAggregate debug messages from process 1234, by message:\n\n```sh\ndtrace -x strsize=4k -n 'bunyan1234:::log-debug{@[copyinstr(arg0)] = count()}'\n```\n\nHave the bunyan CLI pretty-print the traced logs:\n\n```sh\ndtrace -x strsize=4k -qn 'bunyan1234:::log-*{printf(\"%s\", copyinstr(arg0))}' | bunyan\n```\n\nA convenience handle has been made for this:\n\n```sh\nbunyan -p 1234\n```\n\nOn systems that support the\n[`jstack`](http://dtrace.org/blogs/dap/2012/04/25/profiling-node-js/) action\nvia a node.js helper, get a stack backtrace for any debug message that\nincludes the string \"danger!\":\n\n```sh\ndtrace -x strsize=4k -qn 'log-debug/strstr(copyinstr(arg0), \"danger!\") != NULL/{printf(\"\\n%s\", copyinstr(arg0)); jstack()}'\n```\n\nOutput of the above might be:\n\n```\n{\"name\":\"foo\",\"hostname\":\"763bf293-d65c-42d5-872b-4abe25d5c4c7.local\",\"pid\":12747,\"level\":20,\"msg\":\"danger!\",\"time\":\"2012-10-30T18:28:57.115Z\",\"v\":0}\n\n node`0x87e2010\n DTraceProviderBindings.node`usdt_fire_probe+0x32\n DTraceProviderBindings.node`_ZN4node11DTraceProbe5_fireEN2v85LocalINS1_5ValueEEE+0x32d\n DTraceProviderBindings.node`_ZN4node11DTraceProbe4FireERKN2v89ArgumentsE+0x77\n << internal code >>\n (anon) as (anon) at /root/node-bunyan/lib/bunyan.js position 40484\n << adaptor >>\n (anon) as doit at /root/my-prog.js position 360\n (anon) as list.ontimeout at timers.js position 4960\n << adaptor >>\n << internal >>\n << entry >>\n node`_ZN2v88internalL6InvokeEbNS0_6HandleINS0_10JSFunctionEEENS1_INS0_6ObjectEEEiPS5_Pb+0x101\n node`_ZN2v88internal9Execution4CallENS0_6HandleINS0_6ObjectEEES4_iPS4_Pbb+0xcb\n node`_ZN2v88Function4CallENS_6HandleINS_6ObjectEEEiPNS1_INS_5ValueEEE+0xf0\n node`_ZN4node12MakeCallbackEN2v86HandleINS0_6ObjectEEENS1_INS0_8FunctionEEEiPNS1_INS0_5ValueEEE+0x11f\n node`_ZN4node12MakeCallbackEN2v86HandleINS0_6ObjectEEENS1_INS0_6StringEEEiPNS1_INS0_5ValueEEE+0x66\n node`_ZN4node9TimerWrap9OnTimeoutEP10uv_timer_si+0x63\n node`uv__run_timers+0x66\n node`uv__run+0x1b\n node`uv_run+0x17\n node`_ZN4node5StartEiPPc+0x1d0\n node`main+0x1b\n node`_start+0x83\n\n node`0x87e2010\n DTraceProviderBindings.node`usdt_fire_probe+0x32\n DTraceProviderBindings.node`_ZN4node11DTraceProbe5_fireEN2v85LocalINS1_5ValueEEE+0x32d\n DTraceProviderBindings.node`_ZN4node11DTraceProbe4FireERKN2v89ArgumentsE+0x77\n << internal code >>\n (anon) as (anon) at /root/node-bunyan/lib/bunyan.js position 40484\n << adaptor >>\n (anon) as doit at /root/my-prog.js position 360\n (anon) as list.ontimeout at timers.js position 4960\n << adaptor >>\n << internal >>\n << entry >>\n node`_ZN2v88internalL6InvokeEbNS0_6HandleINS0_10JSFunctionEEENS1_INS0_6ObjectEEEiPS5_Pb+0x101\n node`_ZN2v88internal9Execution4CallENS0_6HandleINS0_6ObjectEEES4_iPS4_Pbb+0xcb\n node`_ZN2v88Function4CallENS_6HandleINS_6ObjectEEEiPNS1_INS_5ValueEEE+0xf0\n node`_ZN4node12MakeCallbackEN2v86HandleINS0_6ObjectEEENS1_INS0_8FunctionEEEiPNS1_INS0_5ValueEEE+0x11f\n node`_ZN4node12MakeCallbackEN2v86HandleINS0_6ObjectEEENS1_INS0_6StringEEEiPNS1_INS0_5ValueEEE+0x66\n node`_ZN4node9TimerWrap9OnTimeoutEP10uv_timer_si+0x63\n node`uv__run_timers+0x66\n node`uv__run+0x1b\n node`uv_run+0x17\n node`_ZN4node5StartEiPPc+0x1d0\n node`main+0x1b\n node`_start+0x83\n```\n\n\n# Runtime environments\n\nNode-bunyan supports running in a few runtime environments:\n\n- [Node.js](https://nodejs.org/)\n- [Browserify](http://browserify.org/): See the\n [Browserify section](#browserify) below.\n- [Webpack](https://webpack.github.io/): See the [Webpack section](#webpack) below.\n- [NW.js](http://nwjs.io/)\n\nSupport for other runtime environments is welcome. If you have suggestions,\nfixes, or mentions that node-bunyan already works in some other JavaScript\nruntime, please open an [issue](https://github.com/trentm/node-bunyan/issues/new)\nor a pull request.\n\nThe primary target is Node.js. It is the only environment in which I\nregularly test. If you have suggestions for how to automate testing for other\nenvironments, I'd appreciate feedback on [this automated testing\nissue](https://github.com/trentm/node-bunyan/issues/342).\n\n## Browserify\n\nAs the [Browserify](http://browserify.org/) site says it \"lets you\n`require('modules')` in the browser by bundling up all of your dependencies.\"\nIt is a build tool to run on your node.js script to bundle up your script and\nall its node.js dependencies into a single file that is runnable in the\nbrowser via:\n\n```html\n\n```\n\nAs of version 1.1.0, node-bunyan supports being run via Browserify. The\ndefault [stream](#streams) when running in the browser is one that emits\nraw log records to `console.log/info/warn/error`.\n\nHere is a quick example showing you how you can get this working for your\nscript.\n\n1. Get browserify and bunyan installed in your module:\n\n ```sh\n $ npm install browserify bunyan\n ```\n\n2. An example script using Bunyan, \"play.js\":\n\n ```js\n var bunyan = require('bunyan');\n var log = bunyan.createLogger({name: 'play', level: 'debug'});\n log.trace('this one does not emit');\n log.debug('hi on debug'); // console.log\n log.info('hi on info'); // console.info\n log.warn('hi on warn'); // console.warn\n log.error('hi on error'); // console.error\n ```\n\n3. Build this into a bundle to run in the browser, \"play.browser.js\":\n\n ```sh\n $ ./node_modules/.bin/browserify play.js -o play.browser.js\n ```\n\n4. Put that into an HTML file, \"play.html\":\n\n ```html\n \n \n \n