本文整理汇总了Golang中gopkg/in/inconshreveable/log15/v2.LvlFilterHandler函数的典型用法代码示例。如果您正苦于以下问题:Golang LvlFilterHandler函数的具体用法?Golang LvlFilterHandler怎么用?Golang LvlFilterHandler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LvlFilterHandler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Init
func (d *Daemon) Init() error {
/* Setup the TLS authentication */
certf, keyf, err := shared.ReadMyCert("client.crt", "client.key")
if err != nil {
return err
}
d.certf = certf
d.keyf = keyf
d.tlsConfig, err = shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return err
}
srvlog := log.New(log.Ctx{"module": "client"})
d.log = srvlog
handler := log.StdoutHandler
if quiet {
d.log.SetHandler(log.DiscardHandler())
} else if verbose {
d.log.SetHandler(log.LvlFilterHandler(log.LvlInfo, handler))
} else if debug {
d.log.SetHandler(log.LvlFilterHandler(log.LvlDebug, handler))
} else {
d.log.SetHandler(log.LvlFilterHandler(log.LvlError, handler))
}
d.Run()
return nil
}
示例2: sockHandler
func sockHandler(d *Daemon, w *websocket.Conn) {
r := w.Request()
raddr := r.RemoteAddr
if !d.isTrustedClient(r) {
d.log.Warn("untrusted client connected", log.Ctx{"raddr": raddr})
return
}
d.log.Debug("handing over client connection", log.Ctx{"raddr": raddr})
clog := log.New(log.Ctx{"module": "socks", "raddr": raddr})
handler := log.StdoutHandler
if quiet {
clog.SetHandler(log.DiscardHandler())
} else if verbose {
clog.SetHandler(log.LvlFilterHandler(log.LvlInfo, handler))
} else if debug {
clog.SetHandler(log.LvlFilterHandler(log.LvlDebug, handler))
} else {
clog.SetHandler(log.LvlFilterHandler(log.LvlError, handler))
}
client := &clientConnection{
websocket: w,
log: clog,
raddr: raddr,
}
go client.run()
}
示例3: main
func main() {
flag.Parse()
if helpflag {
flag.Usage()
return
}
logger = log.New()
handler := log.StdoutHandler
if quietflag {
logger.SetHandler(log.DiscardHandler())
} else if verboseflag {
logger.SetHandler(log.LvlFilterHandler(log.LvlInfo, handler))
} else if debugflag {
logger.SetHandler(log.LvlFilterHandler(log.LvlDebug, handler))
} else {
logger.SetHandler(log.LvlFilterHandler(log.LvlError, handler))
}
ldifstore := &ldif.LdifBackend{
Path: "./ldif",
Log: logger.New(log.Ctx{"type": "backend", "backend": "ldif"}),
}
if err := ldifstore.Start(); err != nil {
logger.Error("error loading backend", log.Ctx{"error": err})
os.Exit(1)
}
//Create a new LDAP Server
server := ldap.NewServer(logger)
fallback := &debug.DebugBackend{
Log: logger.New(log.Ctx{"type": "backend", "backend": "debug"}),
}
//Create routes bindings
routes := newRouter(fallback, logger)
// backend specific routes
routes.Bind(ldifstore).BaseDn("dc=enterprise,dc=org").Label("Bind LDIF")
routes.Search(ldifstore).BaseDn("dc=enterprise,dc=org").Label("Search LDIF")
routes.Add(ldifstore).BaseDn("dc=enterprise,dc=org").Label("Add LDIF")
//Attach routes to server
server.Handle(routes)
// listen on 3389 and serve
go server.ListenAndServe(":6389")
// When CTRL+C, SIGINT and SIGTERM signal occurs
// Then stop server gracefully
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
<-ch
close(ch)
server.Stop()
}
示例4: SetLogger
// SetLogger defines the *log.Logger where log messages are sent to.
func SetLogger(syslog string, logfile string, verbose bool, debug bool) error {
Log = log.New()
var handlers []log.Handler
var syshandler log.Handler
// System specific handler
syshandler = GetSystemHandler(syslog, debug)
if syshandler != nil {
handlers = append(handlers, syshandler)
}
// FileHandler
if logfile != "" {
if !PathExists(filepath.Dir(logfile)) {
return fmt.Errorf("Log file path doesn't exist: %s", filepath.Dir(logfile))
}
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlInfo,
log.Must.FileHandler(logfile, log.LogfmtFormat()),
),
)
} else {
handlers = append(handlers, log.Must.FileHandler(logfile, log.LogfmtFormat()))
}
}
// StderrHandler
if verbose || debug {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlInfo,
log.StderrHandler,
),
)
} else {
handlers = append(handlers, log.StderrHandler)
}
} else {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlWarn,
log.StderrHandler,
),
)
}
Log.SetHandler(log.MultiHandler(handlers...))
return nil
}
示例5: SetLogger
// SetLogger defines the *log.Logger where log messages are sent to.
func SetLogger(syslog string, logfile string, verbose bool, debug bool) error {
Log = log.New()
var handlers []log.Handler
// SyslogHandler
if syslog != "" {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.Must.SyslogHandler(syslog, log.LogfmtFormat()),
),
)
} else {
handlers = append(handlers, log.Must.SyslogHandler(syslog, log.LogfmtFormat()))
}
}
// FileHandler
if logfile != "" {
if !PathExists(filepath.Dir(logfile)) {
return fmt.Errorf("Log file path doesn't exist: %s\n", filepath.Dir(logfile))
}
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.Must.FileHandler(logfile, log.LogfmtFormat()),
),
)
} else {
handlers = append(handlers, log.Must.FileHandler(logfile, log.LogfmtFormat()))
}
}
// StderrHandler
if verbose || debug {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.StderrHandler,
),
)
} else {
handlers = append(handlers, log.StderrHandler)
}
}
Log.SetHandler(log.MultiHandler(handlers...))
return nil
}
示例6: InitLog
// InitLog ...
func (logM *LogManager) InitLog() {
var svrlog = log.New(logM.LogContext, logM.LogContext)
svrlog.SetHandler(log.MultiHandler(log.StreamHandler(os.Stderr, log.LogfmtFormat()),
log.LvlFilterHandler(log.LvlError, log.Must.FileHandler(logM.LogDir+logM.ErrorFile, log.JsonFormat())),
log.LvlFilterHandler(log.LvlInfo, log.Must.FileHandler(logM.LogDir+logM.InfoFile, log.JsonFormat())),
log.LvlFilterHandler(log.LvlCrit, log.Must.FileHandler(logM.LogDir+logM.CritFile, log.JsonFormat())),
log.LvlFilterHandler(log.LvlDebug, log.Must.FileHandler(logM.LogDir+logM.DebugFile, log.JsonFormat()))))
logM.Logger = svrlog
}
示例7: SetLogger
// SetLogger defines the *log.Logger where log messages are sent to.
func SetLogger(syslog string, logfile string, verbose bool, debug bool) {
Log = log.New()
var handlers []log.Handler
// SyslogHandler
if syslog != "" {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.Must.SyslogHandler(syslog, log.LogfmtFormat()),
),
)
} else {
handlers = append(handlers, log.Must.SyslogHandler(syslog, log.LogfmtFormat()))
}
}
// FileHandler
if logfile != "" {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.Must.FileHandler(logfile, log.LogfmtFormat()),
),
)
} else {
handlers = append(handlers, log.Must.FileHandler(logfile, log.LogfmtFormat()))
}
}
// StderrHandler
if verbose || debug {
if !debug {
handlers = append(
handlers,
log.LvlFilterHandler(
log.LvlError,
log.StderrHandler,
),
)
} else {
handlers = append(handlers, log.StderrHandler)
}
}
Log.SetHandler(log.MultiHandler(handlers...))
}
示例8: InitLogger
func InitLogger(slvl string) {
if slvl == "" {
slvl = "debug"
}
lvl, err := log.LvlFromString(slvl)
if err != nil {
panic(err)
}
Log.SetHandler(log.LvlFilterHandler(lvl, log.StreamHandler(os.Stdout, log.TerminalFormat())))
return
}
示例9: main
func main() {
var (
zingURL = flag.String("url", "", "Zing MP3 URL to be parsed")
downloadDir = flag.String("dir", ".", "Directory to download into")
)
flag.Parse()
zing.Logger.SetHandler(log.LvlFilterHandler(log.LvlDebug, log.StdoutHandler))
zing.DownloadAlbum(*zingURL, *downloadDir)
}
示例10: Initialize
func (l *Logger) Initialize(logOut string, lvl interface{}) error {
var (
level log.Lvl
err error
)
if l.Context == "" {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
randInt := r.Int()
t := time.Now()
l.Context = fmt.Sprintf("%s#%d", t.Format(time.RFC3339), randInt)
}
if str, ok := lvl.(string); ok {
level, err = log.LvlFromString(str)
if err != nil {
return err
}
} else {
level = lvl.(log.Lvl)
}
l.Logger = log.New(log.Ctx{"context": l.Context})
l.Level = level
if logOut == "STDOUT" {
normalHandler := log.LvlFilterHandler(level, log.StdoutHandler)
errorHandler := log.LvlFilterHandler(level, log.CallerStackHandler("%+v", log.StdoutHandler))
handler := errorMultiHandler(normalHandler, errorHandler)
l.SetHandler(handler)
} else if logOut == "NONE" {
l.SetHandler(log.DiscardHandler())
} else {
fileHandler := log.Must.FileHandler(logOut, log.LogfmtFormat())
normalHandler := log.LvlFilterHandler(level, fileHandler)
errorHandler := log.LvlFilterHandler(level, log.CallerStackHandler("%+v", fileHandler))
handler := errorMultiHandler(normalHandler, errorHandler)
l.SetHandler(handler)
}
return nil
}
示例11: New
func New() *Engine {
// package instance of the helios type
engine := &Engine{
HTTPEngine: gin.Default(),
Socket: initSocket(),
Logger: log.New(),
}
fileHandler, _ := log.FileHandler("./log.debug", log.LogfmtFormat())
engine.SetHandler(log.MultiHandler(log.LvlFilterHandler(log.LvlWarn, fileHandler), log.StreamHandler(os.Stdout, log.TerminalFormat())))
return engine
}
示例12: BenchmarkLog15Discard
func BenchmarkLog15Discard(b *testing.B) {
logger := log.New()
lvl, err := log.LvlFromString("error")
if err != nil {
b.Fatal(err)
}
logger.SetHandler(log.LvlFilterHandler(lvl, log.DiscardHandler()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
logger.Debug("benchmark", "i", i, "b.N", b.N)
}
}
示例13: init
func init() {
// Set global logging levels by the flag, default to WARN if not defined
var level string
flag.StringVar(&level, "level", "WARN", "a string")
flag.StringVar(&confPath, "conf", "config/gologgen.conf", "a string")
flag.Parse()
switch level {
case "DEBUG":
log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlDebug, log15.StdoutHandler))
case "INFO":
log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlInfo, log15.StdoutHandler))
case "WARN":
log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlWarn, log15.StdoutHandler))
case "ERROR":
log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlError, log15.StdoutHandler))
default:
log15.Root().SetHandler(log15.LvlFilterHandler(log15.LvlWarn, log15.StdoutHandler))
}
log = log15.New("function", log15.Lazy{Fn: loghelper.Log15LazyFunctionName})
}
示例14: setFilterHandler
func setFilterHandler(level string, logger log.Logger, handler log.Handler) error {
if level == "none" {
logger.SetHandler(log.DiscardHandler())
return nil
}
lvl, err := log.LvlFromString(level)
if err != nil {
return fmt.Errorf("Bad log level: %v", err)
}
logger.SetHandler(log.LvlFilterHandler(lvl, handler))
return nil
}
示例15: getSystemHandler
// getSystemHandler on Linux writes messages to syslog.
func getSystemHandler(syslog string, debug bool) log.Handler {
// SyslogHandler
if syslog != "" {
if !debug {
return log.LvlFilterHandler(
log.LvlInfo,
log.Must.SyslogHandler(syslog, log.LogfmtFormat()),
)
} else {
return log.Must.SyslogHandler(syslog, log.LogfmtFormat())
}
}
return nil
}