Browse Source

Write log also to a file.

pull/39/head
Jae Kwon 10 years ago
parent
commit
51c70dd8ac
11 changed files with 72 additions and 21 deletions
  1. +2
    -2
      alert/log.go
  2. +3
    -5
      binary/log.go
  3. +2
    -2
      block/log.go
  4. +2
    -2
      cmd/log.go
  5. +2
    -0
      config/log.go
  6. +2
    -2
      consensus/log.go
  7. +51
    -0
      logger/log.go
  8. +2
    -2
      mempool/log.go
  9. +2
    -2
      p2p/log.go
  10. +2
    -2
      p2p/upnp/log.go
  11. +2
    -2
      state/log.go

+ 2
- 2
alert/log.go View File

@ -1,7 +1,7 @@
package alert
import (
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/logger"
)
var log = log15.New("module", "alert")
var log = logger.New("module", "alert")

+ 3
- 5
binary/log.go View File

@ -1,19 +1,17 @@
package binary
import (
"os"
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/logger"
)
var log = log15.New("module", "binary")
var log = logger.New("module", "binary")
func init() {
log.SetHandler(
log15.LvlFilterHandler(
log15.LvlWarn,
//log15.LvlDebug,
log15.StreamHandler(os.Stderr, log15.LogfmtFormat()),
logger.RootHandler(),
),
)
}

+ 2
- 2
block/log.go View File

@ -1,7 +1,7 @@
package block
import (
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/logger"
)
var log = log15.New("module", "block")
var log = logger.New("module", "block")

+ 2
- 2
cmd/log.go View File

@ -1,7 +1,7 @@
package main
import (
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/logger"
)
var log = log15.New("module", "main")
var log = logger.New("module", "main")

+ 2
- 0
config/log.go View File

@ -1,6 +1,8 @@
package config
import (
// We can't use github.com/tendermint/tendermint/logger
// because that would create a dependency cycle.
"github.com/tendermint/log15"
)


+ 2
- 2
consensus/log.go View File

@ -1,7 +1,7 @@
package consensus
import (
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/logger"
)
var log = log15.New("module", "consensus")
var log = logger.New("module", "consensus")

+ 51
- 0
logger/log.go View File

@ -0,0 +1,51 @@
package logger
import (
"fmt"
"os"
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/config"
)
var rootHandler log15.Handler
func init() {
handlers := []log15.Handler{}
// By default, there's a stdout terminal format handler.
handlers = append(handlers, log15.LvlFilterHandler(
log15.LvlDebug,
log15.StreamHandler(os.Stdout, log15.TerminalFormat()),
))
// Maybe also write to a file.
if config.App.GetString("Log.Dir") != "" {
// Create log dir if it doesn't exist
err := os.MkdirAll(config.App.GetString("Log.Dir"), 0700)
if err != nil {
fmt.Printf("Could not create directory: %v", err)
os.Exit(1)
}
// File handler
handlers = append(handlers, log15.LvlFilterHandler(
log15.LvlDebug,
log15.Must.FileHandler(config.App.GetString("Log.Dir")+"/tendermint.log", log15.LogfmtFormat()),
))
}
// Set rootHandler.
rootHandler = log15.MultiHandler(handlers...)
// By setting handlers on the root, we handle events from all loggers.
log15.Root().SetHandler(rootHandler)
}
// See binary/log for an example of usage.
func RootHandler() log15.Handler {
return rootHandler
}
func New(ctx ...interface{}) log15.Logger {
return log15.Root().New(ctx...)
}

+ 2
- 2
mempool/log.go View File

@ -1,7 +1,7 @@
package mempool
import (
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/logger"
)
var log = log15.New("module", "mempool")
var log = logger.New("module", "mempool")

+ 2
- 2
p2p/log.go View File

@ -1,7 +1,7 @@
package p2p
import (
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/logger"
)
var log = log15.New("module", "p2p")
var log = logger.New("module", "p2p")

+ 2
- 2
p2p/upnp/log.go View File

@ -1,7 +1,7 @@
package upnp
import (
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/logger"
)
var log = log15.New("module", "upnp")
var log = logger.New("module", "upnp")

+ 2
- 2
state/log.go View File

@ -1,7 +1,7 @@
package state
import (
"github.com/tendermint/log15"
"github.com/tendermint/tendermint/logger"
)
var log = log15.New("module", "state")
var log = logger.New("module", "state")

Loading…
Cancel
Save