Coder Social home page Coder Social logo

Option to output real JSON about node-bunyan HOT 5 OPEN

domenic avatar domenic commented on August 21, 2024
Option to output real JSON

from node-bunyan.

Comments (5)

weisjohn avatar weisjohn commented on August 21, 2024

+1

from node-bunyan.

trentm avatar trentm commented on August 21, 2024

Sorry to have ignored this ticket for so long. Busy yada yada.

FWIW, my json tool is pretty good for this. For example:

$ node foo.js 
{"name":"myapp","hostname":"banana.local","pid":10837,"level":30,"msg":"start","time":"2013-01-10T04:27:35.875Z","v":0}
{"name":"myapp","hostname":"banana.local","pid":10837,"widget_type":"wuzzle","level":30,"msg":"creating a wuzzle","time":"2013-01-10T04:27:35.876Z","v":0}
{"name":"myapp","hostname":"banana.local","pid":10837,"widget_type":"wuzzle","level":40,"msg":"This wuzzle is woosey.","time":"2013-01-10T04:27:35.876Z","v":0}
{"name":"myapp","hostname":"banana.local","pid":10837,"level":30,"msg":"done","time":"2013-01-10T04:27:35.877Z","v":0}

$ node foo.js  | json -gj
[
  {
    "name": "myapp",
    "hostname": "banana.local",
    "pid": 10848,
    "level": 30,
    "msg": "start",
    "time": "2013-01-10T04:28:33.193Z",
    "v": 0
  },
  {
    "name": "myapp",
    "hostname": "banana.local",
    "pid": 10848,
    "widget_type": "wuzzle",
    "level": 30,
    "msg": "creating a wuzzle",
    "time": "2013-01-10T04:28:33.194Z",
    "v": 0
  },
  {
    "name": "myapp",
    "hostname": "banana.local",
    "pid": 10848,
    "widget_type": "wuzzle",
    "level": 40,
    "msg": "This wuzzle is woosey.",
    "time": "2013-01-10T04:28:33.195Z",
    "v": 0
  },
  {
    "name": "myapp",
    "hostname": "banana.local",
    "pid": 10848,
    "level": 30,
    "msg": "done",
    "time": "2013-01-10T04:28:33.195Z",
    "v": 0
  }
]

If the bunyan-using emits non-Bunyan log lines, then you'll need to strip those out. bunyan --strict can do that:

$ node foo.js 
{"name":"myapp","hostname":"banana.local","pid":10981,"level":30,"msg":"start","time":"2013-01-10T04:31:44.517Z","v":0}
hi there
{"name":"myapp","hostname":"banana.local","pid":10981,"level":30,"msg":"end","time":"2013-01-10T04:31:44.519Z","v":0}

$ node foo.js | bunyan --strict -j
{
  "name": "myapp",
  "hostname": "banana.local",
  "pid": 10991,
  "level": 30,
  "msg": "start",
  "time": "2013-01-10T04:31:50.881Z",
  "v": 0
}
{
  "name": "myapp",
  "hostname": "banana.local",
  "pid": 10991,
  "level": 30,
  "msg": "end",
  "time": "2013-01-10T04:31:50.883Z",
  "v": 0
}

$ node foo.js | bunyan --strict -j | json -gj
[
  {
    "name": "myapp",
    "hostname": "banana.local",
    "pid": 11002,
    "level": 30,
    "msg": "start",
    "time": "2013-01-10T04:31:53.980Z",
    "v": 0
  },
  {
    "name": "myapp",
    "hostname": "banana.local",
    "pid": 11002,
    "level": 30,
    "msg": "end",
    "time": "2013-01-10T04:31:53.982Z",
    "v": 0
  }
]

Is that workable for you?

from node-bunyan.

weisjohn avatar weisjohn commented on August 21, 2024

Thanks for the tip!

On another note, I think it might be helpful to show on the doc page how you can take an existing file and cat it to bunyan... Like:

$ cat my.log | bunyan

from node-bunyan.

trentm avatar trentm commented on August 21, 2024

Noted. Leaving this ticket open to remember to add docs for this kind of thing.

from node-bunyan.

domenic avatar domenic commented on August 21, 2024

I think ideally this would be integrated into bunyan as it's much more discoverable that way, but it sounds like there are definitely good solutions, so I'm OK either way. Especially if it's clearly documented.

from node-bunyan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.