From 7ca744f62ae04b651473d612e53b5ecbc9912253 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 20 Jan 2016 12:47:51 +0100 Subject: [PATCH] Update common/log vendoring Fixes #227 --- .../github.com/prometheus/common/log/log.go | 22 +++--------- .../prometheus/common/log/syslog_formatter.go | 35 +++++++++++++++++++ vendor/vendor.json | 4 +-- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/vendor/github.com/prometheus/common/log/log.go b/vendor/github.com/prometheus/common/log/log.go index 13f09746..07fbfef6 100644 --- a/vendor/github.com/prometheus/common/log/log.go +++ b/vendor/github.com/prometheus/common/log/log.go @@ -41,23 +41,8 @@ func (f levelFlag) Set(level string) error { return nil } -func setSyslogFormatter(appname, local string) error { - if appname == "" { - return fmt.Errorf("missing appname parameter") - } - if local == "" { - return fmt.Errorf("missing local parameter") - } - - fmter, err := newSyslogger(appname, local, origLogger.Formatter) - if err != nil { - fmt.Fprintf(os.Stderr, "error creating syslog formatter: %v\n", err) - origLogger.Errorf("can't connect logger to syslog: %v", err) - return err - } - origLogger.Formatter = fmter - return nil -} +// setSyslogFormatter is nil if the target architecture does not support syslog. +var setSyslogFormatter func(string, string) error func setJSONFormatter() { origLogger.Formatter = &logrus.JSONFormatter{} @@ -87,6 +72,9 @@ func (f logFormatFlag) Set(format string) error { switch u.Opaque { case "syslog": + if setSyslogFormatter == nil { + return fmt.Errorf("system does not support syslog") + } appname := u.Query().Get("appname") facility := u.Query().Get("local") return setSyslogFormatter(appname, facility) diff --git a/vendor/github.com/prometheus/common/log/syslog_formatter.go b/vendor/github.com/prometheus/common/log/syslog_formatter.go index d3c90d19..fd8c6fbe 100644 --- a/vendor/github.com/prometheus/common/log/syslog_formatter.go +++ b/vendor/github.com/prometheus/common/log/syslog_formatter.go @@ -1,3 +1,18 @@ +// Copyright 2015 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !windows,!nacl,!plan9 + package log import ( @@ -8,6 +23,26 @@ import ( "github.com/Sirupsen/logrus" ) +func init() { + setSyslogFormatter = func(appname, local string) error { + if appname == "" { + return fmt.Errorf("missing appname parameter") + } + if local == "" { + return fmt.Errorf("missing local parameter") + } + + fmter, err := newSyslogger(appname, local, origLogger.Formatter) + if err != nil { + fmt.Fprintf(os.Stderr, "error creating syslog formatter: %v\n", err) + origLogger.Errorf("can't connect logger to syslog: %v", err) + return err + } + origLogger.Formatter = fmter + return nil + } +} + var ceeTag = []byte("@cee:") type syslogger struct { diff --git a/vendor/vendor.json b/vendor/vendor.json index 892a6c92..a21cd9e8 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -64,8 +64,8 @@ }, { "path": "github.com/prometheus/common/log", - "revision": "4fdc91a58c9d3696b982e8a680f4997403132d44", - "revisionTime": "2015-10-26T12:04:34+01:00" + "revision": "0a3005bb37bc411040083a55372e77c405f6464c", + "revisionTime": "2016-01-04T14:47:38+01:00" }, { "path": "github.com/prometheus/common/model",