Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #447 from jfrazelle/update-logrus
Browse files Browse the repository at this point in the history
Update logrus to 0.6.6
  • Loading branch information
crosbymichael committed Mar 11, 2015
2 parents f7837f4 + 3e9299d commit 7c8550a
Show file tree
Hide file tree
Showing 24 changed files with 746 additions and 54 deletions.
2 changes: 1 addition & 1 deletion update-vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ clone() {
clone git github.com/codegangsta/cli 1.1.0
clone git github.com/coreos/go-systemd v2
clone git github.com/godbus/dbus v2
clone git github.com/Sirupsen/logrus v0.6.0
clone git github.com/Sirupsen/logrus v0.6.6
clone git github.com/syndtr/gocapability e55e583369

# intentionally not vendoring Docker itself... that'd be a circle :)
5 changes: 2 additions & 3 deletions vendor/src/github.com/Sirupsen/logrus/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ language: go
go:
- 1.2
- 1.3
- 1.4
- tip
install:
- go get github.com/stretchr/testify
- go get github.com/stvp/go-udp-testing
- go get github.com/tobi/airbrake-go
- go get -t ./...
51 changes: 43 additions & 8 deletions vendor/src/github.com/Sirupsen/logrus/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/>&nbsp;[![Build Status](https://travis-ci.org/Sirupsen/logrus.svg?branch=master)](https://travis-ci.org/Sirupsen/logrus)
# Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/>&nbsp;[![Build Status](https://travis-ci.org/Sirupsen/logrus.svg?branch=master)](https://travis-ci.org/Sirupsen/logrus)&nbsp;[![godoc reference](https://godoc.org/github.com/Sirupsen/logrus?status.png)][godoc]

Logrus is a structured logger for Go (golang), completely API compatible with
the standard library logger. [Godoc][godoc]. **Please note the Logrus API is not
yet stable (pre 1.0), the core API is unlikely change much but please version
control your Logrus to make sure you aren't fetching latest `master` on every
build.**
yet stable (pre 1.0). Logrus itself is completely stable and has been used in
many large deployments. The core API is unlikely to change much but please
version control your Logrus to make sure you aren't fetching latest `master` on
every build.**

Nicely color-coded in development (when a TTY is attached, otherwise just
plain text):
Expand Down Expand Up @@ -33,7 +34,7 @@ ocean","size":10,"time":"2014-03-10 19:57:38.562264131 -0400 EDT"}

With the default `log.Formatter = new(logrus.TextFormatter)` when a TTY is not
attached, the output is compatible with the
[l2met](http://r.32k.io/l2met-introduction) format:
[logfmt](http://godoc.org/github.com/kr/logfmt) format:

```text
time="2014-04-20 15:36:23.830442383 -0400 EDT" level="info" msg="A group of walrus emerges from the ocean" animal="walrus" size=10
Expand Down Expand Up @@ -206,11 +207,18 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/hooks/airbrake"
"github.com/Sirupsen/logrus/hooks/syslog"
"log/syslog"
)

func init() {
log.AddHook(new(logrus_airbrake.AirbrakeHook))
log.AddHook(logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, ""))

hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
if err != nil {
log.Error("Unable to connect to local syslog daemon")
} else {
log.AddHook(hook)
}
}
```

Expand All @@ -228,6 +236,15 @@ func init() {
* [`github.com/nubo/hiprus`](https://github.com/nubo/hiprus)
Send errors to a channel in hipchat.

* [`github.com/sebest/logrusly`](https://github.com/sebest/logrusly)
Send logs to Loggly (https://www.loggly.com/)

* [`github.com/johntdyer/slackrus`](https://github.com/johntdyer/slackrus)
Hook for Slack chat.

* [`github.com/wercker/journalhook`](https://github.com/wercker/journalhook).
Hook for logging to `systemd-journald`.

#### Level logging

Logrus has six logging levels: Debug, Info, Warning, Error, Fatal and Panic.
Expand Down Expand Up @@ -307,7 +324,7 @@ The built-in logging formatters are:

Third party logging formatters:

* [`zalgo`](https://github.com/aybabtme/logzalgo): invoking the P͉̫o̳̼̊w̖͈̰͎e̬͔̭͂r͚̼̹̲ ̫͓͉̳͈ō̠͕͖̚f̝͍̠ ͕̲̞͖͑Z̖̫̤̫ͪa͉̬͈̗l͖͎g̳̥o̰̥̅!̣͔̲̻͊̄ ̙̘̦̹̦.
* [`zalgo`](https://github.com/aybabtme/logzalgo): invoking the P͉̫o̳̼̊w̖͈̰͎e̬͔̭͂r͚̼̹̲ ̫͓͉̳͈ō̠͕͖̚f̝͍̠ ͕̲̞͖͑Z̖̫̤̫ͪa͉̬͈̗l͖͎g̳̥o̰̥̅!̣͔̲̻͊̄ ̙̘̦̹̦.

You can define your formatter by implementing the `Formatter` interface,
requiring a `Format` method. `Format` takes an `*Entry`. `entry.Data` is a
Expand All @@ -332,10 +349,28 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
}
```

#### Logger as an `io.Writer`

Logrus can be transormed into an `io.Writer`. That writer is the end of an `io.Pipe` and it is your responsibility to close it.

```go
w := logger.Writer()
defer w.Close()

srv := http.Server{
// create a stdlib log.Logger that writes to
// logrus.Logger.
ErrorLog: log.New(w, "", 0),
}
```

Each line written to that writer will be printed the usual way, using formatters
and hooks. The level for those entries is `info`.

#### Rotation

Log rotation is not provided with Logrus. Log rotation should be done by an
external program (like `logrotated(8)`) that can compress and delete old log
external program (like `logrotate(8)`) that can compress and delete old log
entries. It should not be a feature of the application-level logger.


Expand Down
6 changes: 5 additions & 1 deletion vendor/src/github.com/Sirupsen/logrus/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (entry *Entry) log(level Level, msg string) {
// panic() to use in Entry#Panic(), we avoid the allocation by checking
// directly here.
if level <= PanicLevel {
panic(reader.String())
panic(entry)
}
}

Expand All @@ -126,6 +126,10 @@ func (entry *Entry) Warn(args ...interface{}) {
}
}

func (entry *Entry) Warning(args ...interface{}) {
entry.Warn(args...)
}

func (entry *Entry) Error(args ...interface{}) {
if entry.Logger.Level >= ErrorLevel {
entry.log(ErrorLevel, fmt.Sprint(args...))
Expand Down
53 changes: 53 additions & 0 deletions vendor/src/github.com/Sirupsen/logrus/entry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package logrus

import (
"bytes"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestEntryPanicln(t *testing.T) {
errBoom := fmt.Errorf("boom time")

defer func() {
p := recover()
assert.NotNil(t, p)

switch pVal := p.(type) {
case *Entry:
assert.Equal(t, "kaboom", pVal.Message)
assert.Equal(t, errBoom, pVal.Data["err"])
default:
t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal)
}
}()

logger := New()
logger.Out = &bytes.Buffer{}
entry := NewEntry(logger)
entry.WithField("err", errBoom).Panicln("kaboom")
}

func TestEntryPanicf(t *testing.T) {
errBoom := fmt.Errorf("boom again")

defer func() {
p := recover()
assert.NotNil(t, p)

switch pVal := p.(type) {
case *Entry:
assert.Equal(t, "kaboom true", pVal.Message)
assert.Equal(t, errBoom, pVal.Data["err"])
default:
t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal)
}
}()

logger := New()
logger.Out = &bytes.Buffer{}
entry := NewEntry(logger)
entry.WithField("err", errBoom).Panicf("kaboom %v", true)
}
27 changes: 24 additions & 3 deletions vendor/src/github.com/Sirupsen/logrus/examples/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,26 @@ var log = logrus.New()
func init() {
log.Formatter = new(logrus.JSONFormatter)
log.Formatter = new(logrus.TextFormatter) // default
log.Level = logrus.DebugLevel
}

func main() {
defer func() {
err := recover()
if err != nil {
log.WithFields(logrus.Fields{
"omg": true,
"err": err,
"number": 100,
}).Fatal("The ice breaks!")
}
}()

log.WithFields(logrus.Fields{
"animal": "walrus",
"number": 8,
}).Debug("Started observing beach")

log.WithFields(logrus.Fields{
"animal": "walrus",
"size": 10,
Expand All @@ -23,7 +40,11 @@ func main() {
}).Warn("The group's number increased tremendously!")

log.WithFields(logrus.Fields{
"omg": true,
"number": 100,
}).Fatal("The ice breaks!")
"temperature": -4,
}).Debug("Temperature changes")

log.WithFields(logrus.Fields{
"animal": "orca",
"size": 9009,
}).Panic("It's over 9000!")
}
11 changes: 11 additions & 0 deletions vendor/src/github.com/Sirupsen/logrus/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ var (
std = New()
)

func StandardLogger() *Logger {
return std
}

// SetOutput sets the standard logger output.
func SetOutput(out io.Writer) {
std.mu.Lock()
Expand All @@ -30,6 +34,13 @@ func SetLevel(level Level) {
std.Level = level
}

// GetLevel returns the standard logger level.
func GetLevel() Level {
std.mu.Lock()
defer std.mu.Unlock()
return std.Level
}

// AddHook adds a hook to the standard logger hooks.
func AddHook(hook Hook) {
std.mu.Lock()
Expand Down
14 changes: 7 additions & 7 deletions vendor/src/github.com/Sirupsen/logrus/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ type Formatter interface {
//
// It's not exported because it's still using Data in an opinionated way. It's to
// avoid code duplication between the two default formatters.
func prefixFieldClashes(entry *Entry) {
_, ok := entry.Data["time"]
func prefixFieldClashes(data Fields) {
_, ok := data["time"]
if ok {
entry.Data["fields.time"] = entry.Data["time"]
data["fields.time"] = data["time"]
}

_, ok = entry.Data["msg"]
_, ok = data["msg"]
if ok {
entry.Data["fields.msg"] = entry.Data["msg"]
data["fields.msg"] = data["msg"]
}

_, ok = entry.Data["level"]
_, ok = data["level"]
if ok {
entry.Data["fields.level"] = entry.Data["level"]
data["fields.level"] = data["level"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// with the Airbrake API. You must set:
// * airbrake.Endpoint
// * airbrake.ApiKey
// * airbrake.Environment (only sends exceptions when set to "production")
// * airbrake.Environment
//
// Before using this hook, to send an error. Entries that trigger an Error,
// Fatal or Panic should now include an "error" field to send to Airbrake.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func NewPapertrailHook(host string, port int, appName string) (*PapertrailHook,
// Fire is called when a log event is fired.
func (hook *PapertrailHook) Fire(entry *logrus.Entry) error {
date := time.Now().Format(format)
payload := fmt.Sprintf("<22> %s %s: [%s] %s", date, hook.AppName, entry.Data["level"], entry.Message)
msg, _ := entry.String()
payload := fmt.Sprintf("<22> %s %s: %s", date, hook.AppName, msg)

bytesWritten, err := hook.UDPConn.Write([]byte(payload))
if err != nil {
Expand Down
61 changes: 61 additions & 0 deletions vendor/src/github.com/Sirupsen/logrus/hooks/sentry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Sentry Hook for Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:" />

[Sentry](https://getsentry.com) provides both self-hosted and hosted
solutions for exception tracking.
Both client and server are
[open source](https://github.com/getsentry/sentry).

## Usage

Every sentry application defined on the server gets a different
[DSN](https://www.getsentry.com/docs/). In the example below replace
`YOUR_DSN` with the one created for your application.

```go
import (
"github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/hooks/sentry"
)

func main() {
log := logrus.New()
hook, err := logrus_sentry.NewSentryHook(YOUR_DSN, []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
})

if err == nil {
log.Hooks.Add(hook)
}
}
```

## Special fields

Some logrus fields have a special meaning in this hook,
these are server_name and logger.
When logs are sent to sentry these fields are treated differently.
- server_name (also known as hostname) is the name of the server which
is logging the event (hostname.example.com)
- logger is the part of the application which is logging the event.
In go this usually means setting it to the name of the package.

## Timeout

`Timeout` is the time the sentry hook will wait for a response
from the sentry server.

If this time elapses with no response from
the server an error will be returned.

If `Timeout` is set to 0 the SentryHook will not wait for a reply
and will assume a correct delivery.

The SentryHook has a default timeout of `100 milliseconds` when created
with a call to `NewSentryHook`. This can be changed by assigning a value to the `Timeout` field:

```go
hook, _ := logrus_sentry.NewSentryHook(...)
hook.Timeout = 20*time.Second
```
Loading

0 comments on commit 7c8550a

Please sign in to comment.