# Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/> [![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus) [![GoDoc](https://godoc.org/github.com/sirupsen/logrus?status.svg)](https://godoc.org/github.com/sirupsen/logrus)
Logrus is a structured logger for Go (golang), completely API compatible with
the standard library logger. [Godoc][godoc].
**Seeing weird case-sensitive problems?** Unfortunately, the author failed to
realize the consequences of renaming to lower-case. Due to the Go package
environment, this caused issues. Regretfully, there's no turning back now.
Everything using `logrus` will need to use the lower-case:
`github.com/sirupsen/logrus`. Any package that isn't, should be changed.
I am terribly sorry for this inconvenience. Logrus strives hard for backwards
compatibility, and the author failed to realize the cascading consequences of
such a name-change. To fix Glide, see [these
comments](https://github.com/sirupsen/logrus/issues/553#issuecomment-306591437).
Nicely color-coded in development (when a TTY is attached, otherwise just
plain text):
![Colored](http://i.imgur.com/PY7qMwd.png)
With `log.SetFormatter(&log.JSONFormatter{})`, for easy parsing by logstash
or Splunk:
```json
{"animal":"walrus","level":"info","msg":"A group of walrus emerges from the
ocean","size":10,"time":"2014-03-10 19:57:38.562264131 -0400 EDT"}
{"level":"warning","msg":"The group's number increased tremendously!",
"number":122,"omg":true,"time":"2014-03-10 19:57:38.562471297 -0400 EDT"}
{"animal":"walrus","level":"info","msg":"A giant walrus appears!",
"size":10,"time":"2014-03-10 19:57:38.562500591 -0400 EDT"}
{"animal":"walrus","level":"info","msg":"Tremendously sized cow enters the ocean.",
"size":9,"time":"2014-03-10 19:57:38.562527896 -0400 EDT"}
{"level":"fatal","msg":"The ice breaks!","number":100,"omg":true,
"time":"2014-03-10 19:57:38.562543128 -0400 EDT"}
```
With the default `log.SetFormatter(&log.TextFormatter{})` when a TTY is not
attached, the output is compatible with the
[logfmt](http://godoc.org/github.com/kr/logfmt) format:
```text
time="2015-03-26T01:27:38-04:00" level=debug msg="Started observing beach" animal=walrus number=8
time="2015-03-26T01:27:38-04:00" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
time="2015-03-26T01:27:38-04:00" level=warning msg="The group's number increased tremendously!" number=122 omg=true
time="2015-03-26T01:27:38-04:00" level=debug msg="Temperature changes" temperature=-4
time="2015-03-26T01:27:38-04:00" level=panic msg="It's over 9000!" animal=orca size=9009
time="2015-03-26T01:27:38-04:00" level=fatal msg="The ice breaks!" err=&{0x2082280c0 map[animal:orca size:9009] 2015-03-26 01:27:38.441574009 -0400 EDT panic It's over 9000!} number=100 omg=true
exit status 1
```
#### Case-sensitivity
The organization's name was changed to lower-case--and this will not be changed
back. If you are getting import conflicts due to case sensitivity, please use
the lower-case import: `github.com/sirupsen/logrus`.
#### Example
The simplest way to use Logrus is simply the package-level exported logger:
```go
package main
import (
log "github.com/sirupsen/logrus"
)
func main() {
log.WithFields(log.Fields{
"animal": "walrus",
}).Info("A walrus appears")
}
```
Note that it's completely api-compatible with the stdlib logger, so you can
replace your `log` imports everywhere with `log "github.com/sirupsen/logrus"`
and you'll now have the flexibility of Logrus. You can customize it all you
want:
```go
package main
import (
"os"
log "github.com/sirupsen/logrus"
)
func init() {
// Log as JSON instead of the default ASCII formatter.
log.SetFormatter(&log.JSONFormatter{})
// Output to stdout instead of the default stderr
// Can be any io.Writer, see below for File example
log.SetOutput(os.Stdout)
// Only log the warning severity or above.
log.SetLevel(log.WarnLevel)
}
func main() {
log.WithFields(log.Fields{
"animal": "walrus",
"size": 10,
}).Info("A group of walrus emerges from the ocean")
log.WithFields(log.Fields{
"omg": true,
"number": 122,
}).Warn("The group's number increased tremendously!")
log.WithFields(log.Fields{
"omg": true,
"number": 100,
}).Fatal("The ice breaks!")
// A common pattern is to re-use fields between logging statements by re-using
// the logrus.Entry returned from WithFields()
contextLogger := log.WithFields(log.Fields{
"common": "this is a common field",
"other": "I also should be logged always",
})
contextLogger.Info("I'll be logged with common and other field")
contextLogger.Info("Me too")
}
```
For more advanced usage such as logging to multiple locations from the same
application, you can also create an instance of the `logrus` Logger:
```go
package main
import (
"os"
"github.com/sirupsen/logrus"
)
// Create a new instance of the logger. You can have any number of instances.
var log = logrus.New()
func main() {
// The API for setting attributes is a little different than the package level
// exported logger. See Godoc.
log.Out = os.Stdout
// You could set this to any `io.Writer` such as a file
// file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666)
// if err == nil {
// log.Out = file
// } else {
// log.Info("Failed to log to file, using default stderr")
// }
log.WithFields(logrus.Fields{
"animal": "walrus",
"size": 10,
}).Info("A group of walrus emerges from the ocean")
}
```
#### Fields
Logrus encourages careful, structured logging through logging fields instead of
long, unparseable error messages. For example, instead of: `log.Fatalf("Failed
to send event %s to topic %s with key %d")`, you should log the much more
discoverable:
```go
log.WithFields(log.Fields{
"event": event,
"topic": topic,
"key": key,
}).Fatal("Failed to send event")
```
We've found this API forces you to think about logging in a way that produces
much more useful logging messages. We've been in countless situations where just
a single added field to a log statement that was already there would've saved us
hours. The `WithFields` call is optional.
In general, with Logrus using any of the `printf`-family functions should be
seen as a hint you should add a field, however, you can still use the
`printf`-family functions with Logrus.
#### Default Fields
Often it's helpful to have fields _always_ attached to log statements in an
application or parts of one. For example, you may want to always log the
`request_id` and `user_ip` in the context of a request. Instead of writing
`log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})` on
every line, you can create a `logrus.Entry` to pass around instead:
```go
requestLogger := log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})
requestLogger.Info("something happened on that request") # will log request_id and user_ip
requestLogger.Warn("something not great happened")
```
#### Hooks
You can add hooks for logging levels. For example to send errors to an exception
tracking service on `Error`, `Fatal` and `Panic`, info to StatsD or log to
multiple places simultaneously, e.g. syslog.
Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in
`init`:
```go
import (
log "github.com/sirupsen/logrus"
"gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "aibrake"
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
"log/syslog"
)
func init() {
// Use the Airbrake hook to report errors that have Error severity or above to
// an exception tracker. You can create custom hooks, see the Hooks section.
log.AddHook(airbrake.NewHook(123, "xyz", "production"))
hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
if err
没有合适的资源?快使用搜索试试~ 我知道了~
基于k8s实现的管理平台
共2000个文件
go:1747个
md:201个
json:23个
需积分: 2 0 下载量 156 浏览量
2024-04-08
15:11:32
上传
评论
收藏 49.26MB ZIP 举报
温馨提示
基于Kubernetes(k8s)实现的管理平台是一种利用Kubernetes这一开源容器编排平台来管理和自动化应用程序部署、扩展和运维的工具。Kubernetes提供了一个用于自动部署、扩展和管理容器化应用程序的系统,它通过简化和自动化这些过程,帮助企业更高效地管理其应用程序生命周期。 在这样的管理平台中,Kubernetes的核心特性包括容器编排、服务发现、负载均衡、自动扩展、滚动更新和自我修复等。这些特性使得开发和运维团队能够快速响应市场变化,灵活地部署和调整资源,同时保持系统的高可用性和稳定性。 容器编排是Kubernetes管理平台的核心功能之一,它允许用户定义和运行多容器应用程序,这些容器可以跨多个主机进行调度和管理工作。通过这种方式,Kubernetes能够确保应用程序的各个组件能够按照预期协同工作,同时也能够灵活地应对单个容器或主机的故障。 服务发现和负载均衡是Kubernetes管理平台的另外两个重要特性。服务是Kubernetes中的一个抽象,它定义了一种访问一组相同容器的方式,而负载均衡则确保了流量可以均匀地分配到这些容器上。
资源推荐
资源详情
资源评论
收起资源包目录
基于k8s实现的管理平台 (2000个子文件)
libotr_test_helper.c 6KB
main.cpp 2KB
api.go 601KB
table.go 528KB
storage-gen.go 267KB
data_codec.go 155KB
data_ffjson.go 142KB
api.go 98KB
sql_test.go 82KB
sql.go 79KB
api_test.go 79KB
datastore_v3.pb.go 78KB
scannerc.go 75KB
zmsg.go 74KB
db_test.go 66KB
server.go 65KB
orm_test.go 64KB
swift.go 58KB
defaults.go 54KB
descriptors.go 51KB
driver_test.go 48KB
scan_rr.go 48KB
transport.go 45KB
emitterc.go 44KB
db.go 44KB
golden_test.go 42KB
frame.go 41KB
testsuites.go 40KB
blob.go 39KB
snappy_test.go 39KB
expander_test.go 38KB
glog.go 37KB
acme_test.go 36KB
client.go 36KB
glog.go 36KB
otr.go 35KB
app.go 35KB
repository_test.go 34KB
parserc.go 34KB
s3.go 34KB
s3.go 34KB
encode.go 33KB
packets.go 32KB
cast5.go 32KB
acme.go 32KB
msg.go 31KB
load_test.go 31KB
encode.go 31KB
ocsp_test.go 30KB
decode.go 29KB
autocert.go 29KB
router.go 28KB
types.go 27KB
reader.go 27KB
fakedb_test.go 27KB
trace.go 26KB
command.go 26KB
driver_go18_test.go 26KB
db.go 26KB
session_test.go 26KB
swift.go 25KB
log_service.pb.go 25KB
yamlh.go 25KB
v4.go 25KB
http2_client.go 25KB
properties.go 25KB
quickstart.go 24KB
expander.go 24KB
lib.go 23KB
gcs.go 23KB
scan.go 23KB
ztypes.go 23KB
lets.go 23KB
check.go 23KB
bindata.go 23KB
reconcile.go 22KB
decode.go 22KB
mime.go 22KB
lexer.go 22KB
log.pb.go 22KB
configuration.go 22KB
set_test.go 22KB
server.go 22KB
client.go 21KB
text_parser.go 21KB
repository.go 21KB
mapstructure.go 21KB
apic.go 21KB
templatefunc.go 21KB
server.go 21KB
text.go 21KB
s3.go 21KB
terminal.go 21KB
flag.go 20KB
sum_ref.go 20KB
autocert_test.go 20KB
controller.go 20KB
server.go 20KB
utils.go 20KB
ocsp.go 20KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
进击的代码家
- 粉丝: 2203
- 资源: 204
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 青岛大学人工智能实验二 利用α-β搜索的博弈树算法编写一字棋游戏
- ### 1、项目介绍 本项目Scrapy进行数据爬取,并使用Django框架+PyEcharts实现可视化大屏 效果如下:
- # 微信小程序-健康菜谱 基于微信小程序的一个查找检索菜谱的应用 ### 效果 !动态图(./res/gif/demo
- zabbix-get命令包资源
- 289ssm-mysql-jsp 计算机课程实验管理系统.zip(可运行源码+数据库文件+文档)
- 毕业设计,基于PyQt5实现的可视化界面的Python车牌自动识别系统源码
- 20-天天果园项目.rar
- 26-朴素贝叶斯分类.rar
- 没有安Matlab 也可以 生成FIR抽头系数工具.py
- 自助购药小程序源代码含文档
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功