Skip to content

Commit

Permalink
Merge branch 'master' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
inconshreveable committed Jan 29, 2015
2 parents 7cf5571 + c8460c8 commit fbd9790
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 21 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# log15 [![godoc reference](https://godoc.org/gopkg.in/inconshreveable/log15.v2?status.png)](https://godoc.org/gopkg.in/inconshreveable/log15.v2)

Package log15 provides an opinionated, simple toolkit for best-practice logging that is both human and machine readable. It is modeled after the standard library's io and net/http packages.
Package log15 provides an opinionated, simple toolkit for best-practice logging in Go (golang) that is both human and machine readable. It is modeled after the Go standard library's [`io`](http://golang.org/pkg/io/) and [`net/http`](http://golang.org/pkg/net/http/) packages and is an alternative to the standard library's [`log`](http://golang.org/pkg/log/) package.

## Features
- A simple, easy-to-understand API
Expand All @@ -18,7 +18,9 @@ Package log15 provides an opinionated, simple toolkit for best-practice logging
The API of the master branch of log15 should always be considered unstable. Using a stable version
of the log15 package is supported by gopkg.in. Include your dependency like so:

import log "gopkg.in/inconshreveable/log15.v2"
```go
import log "gopkg.in/inconshreveable/log15.v2"
```

## Examples

Expand Down Expand Up @@ -46,8 +48,8 @@ srvlog.SetHandler(log.MultiHandler(

## FAQ

### The varargs style is brittle and error prone! Can I have type saftey please?
Yes. Use log.Ctx:
### The varargs style is brittle and error prone! Can I have type safety please?
Yes. Use `log.Ctx`:

```go
srvlog := log.New(log.Ctx{"module": "app/server"})
Expand Down
16 changes: 0 additions & 16 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"os"
"reflect"
"sync"
"sync/atomic"
"unsafe"

"gopkg.in/inconshreveable/log15.v2/stack"
)
Expand Down Expand Up @@ -279,20 +277,6 @@ func BufferedHandler(bufSize int, h Handler) Handler {
return ChannelHandler(recs)
}

// swapHandler wraps another handler that may be swapped out
// dynamically at runtime in a thread-safe fashion.
type swapHandler struct {
handler unsafe.Pointer
}

func (h *swapHandler) Log(r *Record) error {
return (*(*Handler)(atomic.LoadPointer(&h.handler))).Log(r)
}

func (h *swapHandler) Swap(newHandler Handler) {
atomic.StorePointer(&h.handler, unsafe.Pointer(&newHandler))
}

// LazyHandler writes all values to the wrapped handler after evaluating
// any lazy functions in the record's context. It is already wrapped
// around StreamHandler and SyslogHandler in this library, you'll only need
Expand Down
26 changes: 26 additions & 0 deletions handler_appengine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// +build appengine

package log15

import "sync"

// swapHandler wraps another handler that may be swapped out
// dynamically at runtime in a thread-safe fashion.
type swapHandler struct {
handler interface{}
lock sync.RWMutex
}

func (h *swapHandler) Log(r *Record) error {
h.lock.RLock()
defer h.lock.RUnlock()

return h.handler.(Handler).Log(r)
}

func (h *swapHandler) Swap(newHandler Handler) {
h.lock.Lock()
defer h.lock.Unlock()

h.handler = newHandler
}
22 changes: 22 additions & 0 deletions handler_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build !appengine

package log15

import (
"sync/atomic"
"unsafe"
)

// swapHandler wraps another handler that may be swapped out
// dynamically at runtime in a thread-safe fashion.
type swapHandler struct {
handler unsafe.Pointer
}

func (h *swapHandler) Log(r *Record) error {
return (*(*Handler)(atomic.LoadPointer(&h.handler))).Log(r)
}

func (h *swapHandler) Swap(newHandler Handler) {
atomic.StorePointer(&h.handler, unsafe.Pointer(&newHandler))
}
2 changes: 1 addition & 1 deletion stack/stack_pool_chan.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !go1.3
// +build !go1.3 appengine

package stack

Expand Down
13 changes: 13 additions & 0 deletions term/terminal_appengine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Based on ssh/terminal:
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build appengine

package term

// IsTty always returns false on AppEngine.
func IsTty(fd uintptr) bool {
return false
}
2 changes: 2 additions & 0 deletions term/terminal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !appengine

package term

import "syscall"
Expand Down

0 comments on commit fbd9790

Please sign in to comment.