本文整理汇总了Golang中github.com/Sirupsen/logrus.AddHook函数的典型用法代码示例。如果您正苦于以下问题:Golang AddHook函数的具体用法?Golang AddHook怎么用?Golang AddHook使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AddHook函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Execute
func (mr *RunCommand) Execute(context *cli.Context) {
svcConfig := &service.Config{
Name: mr.ServiceName,
DisplayName: mr.ServiceName,
Description: defaultDescription,
Arguments: []string{"run"},
Option: service.KeyValue{
"RunWait": mr.runWait,
},
}
service, err := service_helpers.New(mr, svcConfig)
if err != nil {
log.Fatalln(err)
}
if mr.Syslog {
log.SetFormatter(new(log.TextFormatter))
logger, err := service.SystemLogger(nil)
if err == nil {
log.AddHook(&ServiceLogHook{logger, log.InfoLevel})
} else {
log.Errorln(err)
}
}
log.AddHook(&mr.sentryLogHook)
err = service.Run()
if err != nil {
log.Fatalln(err)
}
}
开发者ID:bssthu,项目名称:gitlab-ci-multi-runner,代码行数:33,代码来源:multi.go
示例2: init
func init() {
log.AddHook(&SourceFileHook{LogLevel: log.InfoLevel})
log.AddHook(&SourceFileHook{LogLevel: log.WarnLevel})
log.AddHook(&SourceFileHook{LogLevel: log.ErrorLevel})
log.AddHook(&SourceFileHook{LogLevel: log.PanicLevel})
// initialize values from flag
flag.StringVar(&configDir, "config", "./assets/config/", "Path to the config dir ")
flag.Parse()
}
开发者ID:tomyhero,项目名称:billie,代码行数:10,代码来源:app.go
示例3: Configure
func (app *Application) Configure() error {
var err error
// Set config
if err = app.ReadConfigFile(app.Options.Config); err != nil {
return err
}
// Read config
if err = app.BindConfig(&app.Config); err != nil {
return err
}
// Set log level
var level = log.InfoLevel
if app.Options.Debug {
level = log.DebugLevel
} else if app.Config.Log.Level != "" {
level, err = log.ParseLevel(app.Config.Log.Level)
if err != nil {
log.Warnf("Failed to parse log level: %v", err)
}
}
log.SetLevel(level)
// Set log formatter
var formatter = "text"
if app.Config.Log.Formatter != "" {
formatter = app.Config.Log.Formatter
}
logFormatter, err := ParseLogFormatter(formatter)
if err != nil {
return err
}
log.SetFormatter(logFormatter)
// Add DebugLoggerHook if we are in debug mode
if log.GetLevel() == log.DebugLevel {
log.AddHook(new(DebugLoggerHook))
}
// Add syslog
if app.Config.Log.SyslogName != "" {
syslog_hook, err := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO, app.Config.Log.SyslogName)
if err == nil {
log.AddHook(syslog_hook)
} else {
log.Warnf("Failed to use syslog: %v", err)
}
}
return nil
}
开发者ID:johnny-lai,项目名称:bedrock,代码行数:53,代码来源:application.go
示例4: initLogging
func initLogging() {
// level
level, err := logrus.ParseLevel(viper.GetString("log-level"))
if err != nil {
logrus.WithError(err).Warn(`invalid log level. Defaulting to "info"`)
level = logrus.InfoLevel
}
logrus.SetLevel(level)
// format
switch viper.GetString("log-format") {
case "text":
logrus.SetFormatter(new(logrus.TextFormatter))
case "json":
logrus.SetFormatter(new(logrus.JSONFormatter))
default:
logrus.SetFormatter(new(logrus.TextFormatter))
logrus.WithField("format", viper.GetString("log-format")).Warn(`invalid log format. Defaulting to "text"`)
}
// output
dest, err := url.Parse(viper.GetString("log-destination"))
if err != nil {
logrus.WithError(err).WithField("destination", viper.GetString("log-destination")).Error(`invalid log destination. Defaulting to "stdout:"`)
dest.Scheme = "stdout"
}
switch dest.Scheme {
case "stdout":
// default, we don't need to do anything
case "file":
logrus.AddHook(lfshook.NewHook(lfshook.PathMap{
logrus.DebugLevel: dest.Opaque,
logrus.InfoLevel: dest.Opaque,
logrus.WarnLevel: dest.Opaque,
logrus.ErrorLevel: dest.Opaque,
logrus.FatalLevel: dest.Opaque,
}))
case "journald":
journalhook.Enable()
case "syslog":
hook, err := logrus_syslog.NewSyslogHook(dest.Fragment, dest.Host, syslog.LOG_DEBUG, dest.User.String())
if err != nil {
logrus.WithError(err).Error("could not configure syslog hook")
} else {
logrus.AddHook(hook)
}
default:
logrus.WithField("destination", viper.GetString("log-destination")).Warn(`invalid log destination. Defaulting to "stdout:"`)
}
}
开发者ID:asteris-llc,项目名称:vaultfs,代码行数:51,代码来源:utils.go
示例5: setupFileLogging
func setupFileLogging(logFile string) {
log.Printf("Logging to file=[%s]", logFile)
logrusFileHook := lfshook.NewHook(lfshook.PathMap{
log.InfoLevel: logFile, log.WarnLevel: logFile, log.ErrorLevel: logFile, log.FatalLevel: logFile, log.PanicLevel: logFile,
})
log.AddHook(logrusFileHook)
}
开发者ID:ashmckenzie,项目名称:sshoney,代码行数:7,代码来源:main.go
示例6: init
func init() {
log.SetOutput(os.Stderr)
log.SetLevel(log.DebugLevel)
papertrailHost := os.Getenv("PAPERTRAIL_HOST")
if papertrailHost == "" {
return
}
papertrailPort := os.Getenv("PAPERTRAIL_PORT")
port, err := strconv.Atoi(papertrailPort)
if err != nil {
log.Fatalf("Error getting Papertrail port: %v", err)
}
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Error getting hostname: %v", err)
}
hook, err := logrus_papertrail.NewPapertrailHook(
&logrus_papertrail.Hook{
Host: papertrailHost,
Port: port,
Hostname: hostname,
Appname: os.Getenv("APP_NAME"),
},
)
if err != nil {
log.Fatalf("Error building Papertrail hook: %v", err)
}
log.AddHook(hook)
}
开发者ID:codequest-eu,项目名称:burnafterreading,代码行数:29,代码来源:server.go
示例7: configureSyslog
func configureSyslog(syslogParam string) {
var err error
var hook log.Hook
// disable colors if we're writing to syslog *and* we're the default text
// formatter, because the tty detection is useless here.
if tf, ok := log.StandardLogger().Formatter.(*log.TextFormatter); ok {
tf.DisableColors = true
}
if syslogParam == "kernel" {
hook, err = logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO, "netplugin")
if err != nil {
log.Fatalf("Could not connect to kernel syslog")
}
} else {
u, err := url.Parse(syslogParam)
if err != nil {
log.Fatalf("Could not parse syslog spec: %v", err)
}
hook, err = logrus_syslog.NewSyslogHook(u.Scheme, u.Host, syslog.LOG_INFO, "netplugin")
if err != nil {
log.Fatalf("Could not connect to syslog: %v", err)
}
}
log.AddHook(hook)
}
开发者ID:karamsivia,项目名称:netplugin,代码行数:29,代码来源:netd.go
示例8: Execute
func (c *RunCommand) Execute(context *cli.Context) {
svcConfig := &service.Config{
Name: c.ServiceName,
DisplayName: c.ServiceName,
Description: defaultDescription,
Arguments: []string{"run"},
}
service, err := service_helpers.New(c, svcConfig)
if err != nil {
log.Fatalln(err)
}
if c.Syslog {
logger, err := service.SystemLogger(nil)
if err == nil {
log.AddHook(&ServiceLogHook{logger})
} else {
log.Errorln(err)
}
}
err = service.Run()
if err != nil {
log.Fatalln(err)
}
}
开发者ID:zhangxq5012,项目名称:gitlab-ci-multi-runner,代码行数:27,代码来源:multi.go
示例9: Connect
func Connect() bool {
success := false
logrus.SetFormatter(&logrus.JSONFormatter{})
if !debugFlag {
logrus.SetOutput(ioutil.Discard)
} else {
logrus.SetOutput(os.Stdout)
}
if fluentdServer != "" {
host, port, err := net.SplitHostPort(fluentdServer)
if err != nil {
LogError(fmt.Sprintf("Unable to split to fluentd server [%s]!\n", fluentdServer), err.Error())
}
portInt, err := strconv.Atoi(port)
if err != nil {
LogError(fmt.Sprintf("Unable to convert port format [%s]!\n", port), err.Error())
}
hook := logrus_fluent.NewHook(host, portInt)
LogStd(fmt.Sprintf("Received hook to fluentd server [%s]!\n", fluentdServer), false)
logrus.AddHook(hook)
success = true
}
return success
}
开发者ID:shinji62,项目名称:firehose-to-fluentd,代码行数:30,代码来源:logging.go
示例10: setupLogging
func setupLogging() {
if config.Settings.Moire.Debug {
log.Info("Logging in DEBUG mode")
log.SetLevel(log.DebugLevel)
}
// log.SetFlags(log.Ldate | log.Ltime | log.Llongfile)
log.SetFormatter(&log.TextFormatter{})
if config.Settings.Moire.SentryDSN != "" {
levels := []log.Level{
log.PanicLevel,
log.FatalLevel,
log.ErrorLevel,
}
hook, err := logrus_sentry.NewSentryHook(config.Settings.Moire.SentryDSN, levels)
if err != nil {
log.Error("Unable to connect to sentry")
} else {
log.Info("Adding Sentry Hook")
log.AddHook(hook)
}
}
}
开发者ID:josjevv,项目名称:moire,代码行数:25,代码来源:setup.go
示例11: loadConfiguration
// loadConfiguration loads the configuration of application
func loadConfiguration(app *AppConfig, rdis *RedisConfig, nats *NatsConfig) {
err := envconfig.Process(ServiceName, app)
if err != nil {
log.Panicln(err)
}
err = envconfig.Process("redis", rdis)
if err != nil {
log.Panicln(err)
}
err = envconfig.Process("nats", nats)
if err != nil {
log.Panicln(err)
}
if len(os.Getenv(KeyLogly)) > 0 {
log.Printf("Loading logly token %s \n", os.Getenv(KeyLogly))
hook := logrusly.NewLogglyHook(os.Getenv(KeyLogly),
app.Host,
log.InfoLevel,
app.Name)
log.AddHook(hook)
}
log.Println("#### LOADED CONFIG #####")
log.Printf("REDIS_URI: %s \n", rdis.URI)
log.Printf("NATS_ENDPOINT: %s \n", nats.Endpoint)
}
开发者ID:suricatatalk,项目名称:gate,代码行数:27,代码来源:gate.go
示例12: getConfig
func getConfig() (*types.Config, error) {
app.Validate(validateParams)
kingpin.HelpFlag.Short('h')
app.Flag("version", "Print application version and exit").PreAction(printVersion).Short('v').Bool()
kingpin.MustParse(app.Parse(os.Args[1:]))
c := &types.Config{
Consul: *consul,
Marathon: *marathon,
ResyncInterval: *resyncInterval,
DryRun: *enableDryRun,
}
// Setup the logging.
level, err := log.ParseLevel(*logLevel)
if err != nil {
return nil, err
}
log.SetFormatter(&prefixed.TextFormatter{
ForceColors: *forceColors,
})
log.SetLevel(level)
if *enableSyslog {
hook, err := logrusSyslog.NewSyslogHook("", "", syslog.LOG_DEBUG, app.Name)
if err != nil {
return nil, err
}
log.AddHook(hook)
}
return c, nil
}
开发者ID:x-cray,项目名称:marathon-registrator,代码行数:35,代码来源:registrator.go
示例13: SetupLogging
// SetupLogging sets up logging. if token is not and empty string a rollbar
// hook is added with the environment set to env. The log formatter is set to a
// TextFormatter with timestamps disabled, which is suitable for use on Heroku.
func SetupLogging(token, env string) {
log.SetFormatter(&log.TextFormatter{DisableTimestamp: true})
if token != "" {
log.AddHook(&Hook{Client: roll.New(token, env)})
}
}
开发者ID:heroku,项目名称:log-iss,代码行数:10,代码来源:rollrus.go
示例14: setupSentry
func (i *CLI) setupSentry() {
if i.Config.SentryDSN == "" {
return
}
levels := []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
}
if i.Config.SentryHookErrors {
levels = append(levels, logrus.ErrorLevel)
}
sentryHook, err := NewSentryHook(i.Config.SentryDSN, levels)
if err != nil {
i.logger.WithField("err", err).Error("couldn't create sentry hook")
}
logrus.AddHook(sentryHook)
err = raven.SetDSN(i.Config.SentryDSN)
if err != nil {
i.logger.WithField("err", err).Error("couldn't set DSN in raven")
}
}
开发者ID:apjanke,项目名称:worker,代码行数:27,代码来源:cli.go
示例15: Connect
func Connect() bool {
success := false
logrus.SetFormatter(&logrus.JSONFormatter{})
if !debugFlag {
logrus.SetOutput(ioutil.Discard)
} else {
logrus.SetOutput(os.Stdout)
}
if syslogServer != "" {
hook, err := logrus_syslog.NewSyslogHook("tcp", syslogServer, syslog.LOG_INFO, "doppler")
if err != nil {
LogError(fmt.Sprintf("Unable to connect to syslog server [%s]!\n", syslogServer), err.Error())
} else {
LogStd(fmt.Sprintf("Received hook to syslog server [%s]!\n", syslogServer), false)
logrus.AddHook(hook)
success = true
}
}
return success
}
开发者ID:msschwartz,项目名称:firehose-to-syslog,代码行数:25,代码来源:logging.go
示例16: setupLogging
func setupLogging(token, env string, levels []log.Level) {
log.SetFormatter(&log.TextFormatter{DisableTimestamp: true})
if token != "" {
log.AddHook(&Hook{Client: roll.New(token, env), triggers: levels})
}
}
开发者ID:tenex,项目名称:rollrus,代码行数:7,代码来源:rollrus.go
示例17: init
func init() {
// 初始化日志
logrus.SetFormatter(&logrus.JSONFormatter{})
log.SetOutput(logrus.StandardLogger().Out)
// 初始化配置
Config = loadConfig()
lv, err := logrus.ParseLevel(Config.LogLevel)
if err != nil {
logrus.WithError(err).Warn("解析日志等级出错")
lv = logrus.DebugLevel
}
logrus.SetLevel(lv)
if Config.ReportOn {
hook, err := logrus_mail.NewMailAuthHook(Config.AppName,
Config.MailerHost,
Config.MailerPort,
Config.MailerUser,
Config.MailReceiver,
Config.MailerUser,
Config.MailerPass)
if err == nil {
logrus.AddHook(hook)
}
}
exeRoot := filepath.Dir(os.Args[0])
f, err := os.OpenFile(filepath.Join(exeRoot, "retask.log"), os.O_APPEND|os.O_CREATE, os.ModePerm)
if err != nil {
logrus.WithError(err).Fatal("打开日志文件失败")
}
logrus.SetOutput(f)
}
开发者ID:duanqy,项目名称:retask,代码行数:34,代码来源:main.go
示例18: init
func init() {
hook, err := logredis.NewHook("localhost", 6379, "my_redis_key", "v0", log.DebugLevel, false, 1000)
if err == nil {
log.AddHook(hook)
} else {
log.Error(err)
}
}
开发者ID:FlxOne,项目名称:logrus-redis-hook,代码行数:8,代码来源:main.go
示例19: NewGlobal
// Installs a test hook for the global logger.
func NewGlobal() *Hook {
hook := new(Hook)
logrus.AddHook(hook)
return hook
}
开发者ID:ContiGuy,项目名称:conti-gui,代码行数:9,代码来源:test.go
示例20: Init
func Init() {
initSender()
logrus.SetFormatter(&formatter{})
logrus.AddHook(&logHook{})
logrus.SetOutput(os.Stderr)
logrus.SetLevel(logrus.InfoLevel)
}
开发者ID:pathcode,项目名称:pritunl-client-electron,代码行数:8,代码来源:logger.go
注:本文中的github.com/Sirupsen/logrus.AddHook函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论