代码拉取完成,页面将自动刷新
同步操作将从 水不要鱼/logit 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// Copyright 2020 Ye Zi Jie. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: FishGoddess
// Email: fishgoddess@qq.com
// Created at 2020/04/27 22:44:04
package logit
func init() {
registerDebugLevelHandler()
registerInfoLevelHandler()
registerWarnLevelHandler()
registerErrorLevelHandler()
}
// levelBasedHandler is a level sensitive handler.
// It only handles the specific level of this handler, so you can use different handlers
// to handle logs in different levels. For example, you want debug/info/warn level logs are
// written to log file "xxx.log" and error level logs are written to log file "xxx.error.log",
// maybe written to log server, too, then you can use this handler to do it.
type levelBasedHandler struct {
// level is the level of log that can be handled by this handler.
// See logit.Level.
level Level
// handlers is all handlers used to handle logs in level.
// See logit.Handler.
handlers []Handler
}
// NewLevelBasedHandler returns a handler handled logs in level.
// You can add more than one handler to this handler. This handler is just like a
// wrapper wrapping some handlers.
func NewLevelBasedHandler(level Level, handlers ...Handler) Handler {
return &levelBasedHandler{
level: level,
handlers: handlers,
}
}
// Handle handles a log with handlers in lbh.
// Notice that the handling process will be interrupted if one of them
// returned false. However, this method will always return true, so the handlers
// after it will always be used.
func (lbh *levelBasedHandler) Handle(log *Log) bool {
if log.Level() == lbh.level {
for _, handler := range lbh.handlers {
if !handler.Handle(log) {
break
}
}
}
return true
}
// handlersOf returns handlers parsed from params.
func handlersOf(params map[string]interface{}) []Handler {
handlers := make([]Handler, 0, len(params)+2)
for name, paramsOfHandler := range params {
handlers = append(handlers, handlerOf(name, paramsOfHandler.(map[string]interface{})))
}
return handlers
}
// ================================ debug level handler ================================
// registerDebugLevelHandler registers debug level handler which
// only handles logs in debug level.
//
// For config:
// If you want to use this handler in your logger by config file, try this:
//
// "handlers": {
// "debug": {
// "console": {}
// }
// }
//
// You should always know that this handler is a wrapper, so you must add some other
// handlers to it otherwise it will do nothing. All registered handlers can be added
// to it, even one more debug level handler. Now, you know it is only a filter that filters
// non-debug level logs. As for what params should be written in handlers inside are dependent
// to different handlers. Check other handlers' documents to know more about information.
// See logit.Handler.
func registerDebugLevelHandler() {
RegisterHandler("debug", func(params map[string]interface{}) Handler {
return NewLevelBasedHandler(DebugLevel, handlersOf(params)...)
})
}
// ================================ info level handler ================================
// registerInfoLevelHandler registers info level handler which
// only handles logs in info level.
//
// For config:
// If you want to use this handler in your logger by config file, try this:
//
// "handlers": {
// "info": {
// "console": {}
// }
// }
//
// You should always know that this handler is a wrapper, so you must add some other
// handlers to it otherwise it will do nothing. All registered handlers can be added
// to it, even one more info level handler. Now, you know it is only a filter that filters
// non-info level logs. As for what params should be written in handlers inside are dependent
// to different handlers. Check other handlers' documents to know more about information.
// See logit.Handler.
func registerInfoLevelHandler() {
RegisterHandler("info", func(params map[string]interface{}) Handler {
return NewLevelBasedHandler(InfoLevel, handlersOf(params)...)
})
}
// ================================ warn level handler ================================
// registerWarnLevelHandler registers warn level handler which
// only handles logs in warn level.
//
// For config:
// If you want to use this handler in your logger by config file, try this:
//
// "handlers": {
// "warn": {
// "console": {}
// }
// }
//
// You should always know that this handler is a wrapper, so you must add some other
// handlers to it otherwise it will do nothing. All registered handlers can be added
// to it, even one more warn level handler. Now, you know it is only a filter that filters
// non-warn level logs. As for what params should be written in handlers inside are dependent
// to different handlers. Check other handlers' documents to know more about information.
// See logit.Handler.
func registerWarnLevelHandler() {
RegisterHandler("warn", func(params map[string]interface{}) Handler {
return NewLevelBasedHandler(WarnLevel, handlersOf(params)...)
})
}
// ================================ error level handler ================================
// registerErrorLevelHandler registers error level handler which
// only handles logs in error level.
//
// For config:
// If you want to use this handler in your logger by config file, try this:
//
// "handlers": {
// "error": {
// "console": {}
// }
// }
//
// You should always know that this handler is a wrapper, so you must add some other
// handlers to it otherwise it will do nothing. All registered handlers can be added
// to it, even one more error level handler. Now, you know it is only a filter that filters
// non-error level logs. As for what params should be written in handlers inside are dependent
// to different handlers. Check other handlers' documents to know more about information.
// See logit.Handler.
func registerErrorLevelHandler() {
RegisterHandler("error", func(params map[string]interface{}) Handler {
return NewLevelBasedHandler(ErrorLevel, handlersOf(params)...)
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。