Add LogFormat flag

This commit is contained in:
Taylor Gerring 2015-01-21 10:17:07 -06:00
parent acdc19d1b7
commit bdf99e0981
4 changed files with 13 additions and 3 deletions

View File

@ -57,6 +57,7 @@ var (
ConfigFile string ConfigFile string
DebugFile string DebugFile string
LogLevel int LogLevel int
LogFormat string
Dump bool Dump bool
DumpHash string DumpHash string
DumpNumber int DumpNumber int
@ -110,6 +111,7 @@ func Init() {
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file") flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)") flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)") flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
flag.StringVar(&LogFormat, "logformat", "std", "logformat: std,raw)")
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0") flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false") flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block") flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")

View File

@ -67,6 +67,7 @@ func main() {
DataDir: Datadir, DataDir: Datadir,
LogFile: LogFile, LogFile: LogFile,
LogLevel: LogLevel, LogLevel: LogLevel,
LogFormat: LogFormat,
Identifier: Identifier, Identifier: Identifier,
MaxPeers: MaxPeer, MaxPeers: MaxPeer,
Port: OutboundPort, Port: OutboundPort,

View File

@ -29,6 +29,7 @@ type Config struct {
DataDir string DataDir string
LogFile string LogFile string
LogLevel int LogLevel int
LogFormat string
KeyRing string KeyRing string
MaxPeers int MaxPeers int
@ -80,7 +81,7 @@ type Ethereum struct {
func New(config *Config) (*Ethereum, error) { func New(config *Config) (*Ethereum, error) {
// Boostrap database // Boostrap database
logger := ethlogger.New(config.DataDir, config.LogFile, config.LogLevel) logger := ethlogger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
db, err := ethdb.NewLDBDatabase("blockchain") db, err := ethdb.NewLDBDatabase("blockchain")
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -18,7 +18,7 @@ func openLogFile(datadir string, filename string) *os.File {
return file return file
} }
func New(datadir string, logFile string, logLevel int) LogSystem { func New(datadir string, logFile string, logLevel int, logFormat string) LogSystem {
var writer io.Writer var writer io.Writer
if logFile == "" { if logFile == "" {
writer = os.Stdout writer = os.Stdout
@ -26,7 +26,13 @@ func New(datadir string, logFile string, logLevel int) LogSystem {
writer = openLogFile(datadir, logFile) writer = openLogFile(datadir, logFile)
} }
sys := NewStdLogSystem(writer, log.LstdFlags, LogLevel(logLevel)) var sys LogSystem
switch logFormat {
case "raw":
sys = NewRawLogSystem(writer, 0, LogLevel(logLevel))
default:
sys = NewStdLogSystem(writer, log.LstdFlags, LogLevel(logLevel))
}
AddLogSystem(sys) AddLogSystem(sys)
return sys return sys