本文整理汇总了Golang中gopkg/in/inconshreveable/log15/v2.LvlFilterHandler函数的典型用法代码示例。如果您正苦于以下问题:Golang LvlFilterHandler函数的具体用法?Golang LvlFilterHandler怎么用?Golang LvlFilterHandler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LvlFilterHandler函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:jsimonetti,项目名称:tlstun,代码行数:31,代码来源:daemon.go
示例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()
}
开发者ID:jsimonetti,项目名称:tlstun,代码行数:30,代码来源:handler.go
示例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()
}
开发者ID:jsimonetti,项目名称:ldapserv,代码行数:60,代码来源:main.go
示例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
}
开发者ID:rockstar,项目名称:lxd,代码行数:60,代码来源:log.go
示例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
}
开发者ID:RuneTM,项目名称:lxd,代码行数:59,代码来源:log.go
示例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
}
开发者ID:amosunfemi,项目名称:xtremepay,代码行数:13,代码来源:log_manager.go
示例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...))
}
开发者ID:joker042,项目名称:lxd,代码行数:53,代码来源:log.go
示例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
}
开发者ID:marsmensch,项目名称:blobstash,代码行数:11,代码来源:logger.go
示例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)
}
开发者ID:Taik,项目名称:zing-mp3,代码行数:11,代码来源:main.go
示例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
}
开发者ID:cloud66,项目名称:cxlogger,代码行数:41,代码来源:logger.go
示例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
}
开发者ID:begizi,项目名称:helios-server,代码行数:13,代码来源:helios.go
示例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)
}
}
开发者ID:yunhor,项目名称:pgx,代码行数:13,代码来源:bench_test.go
示例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})
}
开发者ID:gadouryd,项目名称:gologgen,代码行数:23,代码来源:main.go
示例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
}
开发者ID:jackc,项目名称:tpr,代码行数:14,代码来源:main.go
示例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
}
开发者ID:ccsblueboy,项目名称:lxd,代码行数:16,代码来源:log_posix.go
示例16: BenchmarkSelectWithLoggingErrorWithLog15
func BenchmarkSelectWithLoggingErrorWithLog15(b *testing.B) {
connConfig := *defaultConnConfig
logger := log.New()
lvl, err := log.LvlFromString("error")
if err != nil {
b.Fatal(err)
}
logger.SetHandler(log.LvlFilterHandler(lvl, log.DiscardHandler()))
connConfig.Logger = logger
connConfig.LogLevel = pgx.LogLevelError
conn := mustConnect(b, connConfig)
defer closeConn(b, conn)
benchmarkSelectWithLog(b, conn)
}
开发者ID:yunhor,项目名称:pgx,代码行数:16,代码来源:bench_test.go
示例17: ConfigureRootLogger
func ConfigureRootLogger() {
sh := log.StreamHandler(colorable.NewColorableStdout(), log.TerminalFormat())
logLevel := log.LvlInfo
if showDebug == true {
logLevel = log.LvlDebug
} else {
_, found := os.LookupEnv("DEBUG")
if found == true {
logLevel = log.LvlDebug
}
}
fh := log.LvlFilterHandler(logLevel, sh)
cfh := log.CallerFileHandler(fh)
log.Root().SetHandler(cfh)
}
开发者ID:dsoprea,项目名称:go-pathfingerprint,代码行数:18,代码来源:log.go
示例18: Start
// Start Logger service
func (self *Logger) Start() {
var err error
self.Logger = log.New()
if self.Release {
self.Level, err = log.LvlFromString("error")
if err != nil {
fmt.Println(err)
}
} else {
self.Level, err = log.LvlFromString("debug")
if err != nil {
fmt.Println(err)
}
}
self.Logger.SetHandler(log.LvlFilterHandler(self.Level, log.StdoutHandler))
// self.SetHandler(log.LvlFilterHandler(lvl, log.DiscardHandler()))
self.Info("starting Logger service...")
}
开发者ID:grengojbo,项目名称:ads,代码行数:19,代码来源:logger.go
示例19: setSettings
func setSettings(level int, filename string) {
logFilename = filename
debug = level
filehandler := log.Must.FileHandler(filename, log.LogfmtFormat())
handler := log.MultiHandler(
filehandler,
log.StreamHandler(os.Stderr, log.TerminalFormat()))
if debug > 1 {
handler = log.CallerStackHandler("%+v", handler)
} else {
handler = log.CallerFileHandler(handler)
}
if debug < 1 {
handler = log.LvlFilterHandler(log.LvlInfo, handler)
}
log.Root().SetHandler(handler)
log.Info("Logging started", "level", debug, "log_file", logFilename)
}
开发者ID:KarolBedkowski,项目名称:secproxy,代码行数:19,代码来源:logging.go
示例20: BenchmarkLog15TextNegative
func BenchmarkLog15TextNegative(b *testing.B) {
stream := &blackholeStream{}
logger := log.New()
logger.SetHandler(log.LvlFilterHandler(
log.LvlError,
log.StreamHandler(stream, log.LogfmtFormat())),
)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("The quick brown fox jumps over the lazy dog")
}
})
if stream.WriteCount() != uint64(0) {
b.Fatalf("Log write count")
}
}
开发者ID:pjvds,项目名称:go-loggers-bench,代码行数:19,代码来源:log15_test.go
注:本文中的gopkg/in/inconshreveable/log15/v2.LvlFilterHandler函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论