Skip to content

Commit

Permalink
Logger clone helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsyu1 committed May 19, 2016
1 parent a98235b commit 032333f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cfg_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package seelog
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"os"
)
Expand Down Expand Up @@ -186,3 +187,26 @@ func LoggerFromCustomReceiver(receiver CustomReceiver) (LoggerInterface, error)

return createLoggerFromFullConfig(conf)
}

func CloneLogger(logger LoggerInterface) (LoggerInterface, error) {
switch logger := logger.(type) {
default:
return nil, fmt.Errorf("unexpected type %T", logger)
case *asyncAdaptiveLogger:
clone, err := NewAsyncAdaptiveLogger(logger.commonLogger.config, logger.minInterval, logger.maxInterval, logger.criticalMsgCount)
if err != nil {
return nil, err
}
return clone, nil
case *asyncLoopLogger:
return NewAsyncLoopLogger(logger.commonLogger.config), nil
case *asyncTimerLogger:
clone, err := NewAsyncTimerLogger(logger.commonLogger.config, logger.interval)
if err != nil {
return nil, err
}
return clone, nil
case *syncLogger:
return NewSyncLogger(logger.commonLogger.config), nil
}
}

0 comments on commit 032333f

Please sign in to comment.