• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

trevoro/bash-bunyan

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

trevoro/bash-bunyan

开源软件地址:

https://github.com/trevoro/bash-bunyan

开源编程语言:

Shell 100.0%

开源软件介绍:

Bash-Bunyan

This tool is based off trentms excellent node-bunyan utility. It's used for creating structured logs using the JSON format. The output is JSON which can be piped to either the 'bunyan' tool itself, or to another JSON parser or to a file.

Usage

To use bash-bunyan in your bash script, source the 'bunyan' script then use one of the level names to log directly. ex:

$ cat example.sh
#!/usr/bin/bash

. includes/bunyan

info "this is an info message"
$
~
$ sh example.sh | json 
{
  "name": "example.sh",
  "hostname": "mac.local",
  "pid": 49121,
  "level": 30,
  "msg": "this is an info message",
  "time": "2012-03-24T02:48:21Z",
  "v": 0
}

Levels

When you include bunyan you will automatically inherit functions which correspond to the log levels. These functions are

  • trace (60): logging from external libraries
  • debug (50): verbose debug information
  • info (40): detail on regular information
  • warn (30): something an operation should pay attention to
  • error (20): fatal for a request / action
  • fatal (10): the application exited because of some error

To change the loglevel set the '__bunyanLevel to the appropriate level you care about. Anything under that level will not be logged. By default, the level is set to 'info'.

Settings

bash-bunyan doesn't have nearly the granularity of node-bunyan, but you can set the name of the process reported in bunyan by setting the '__bunyanName' variable. This variable will be set automatically in your script when you source the bunyan include file. ex:

$ cat example2.sh
#!/usr/bin/bash

. includes/bunyan
__bunyanName='super'
info 'hello world'
~
$ sh example2.sh | bunyan
[2012-03-24T02:47:15Z]  INFO: super/49105 on mac.local: hello world



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap