1 Star 0 Fork 14

rob/logit

forked from 水不要鱼/logit 
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
error.go 1.36 KB
Copy Edit Raw Blame History
zijieye authored 2022-10-08 01:25 +08:00 . 再次转移仓库
// Copyright 2022 FishGoddess. 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.
package main
import (
"errors"
"fmt"
"github.com/FishGoddess/logit"
"github.com/FishGoddess/logit/support/global"
)
// uselessWriter is a demo writer to demonstrate the error handling function.
type uselessWriter struct{}
func (uw uselessWriter) Write(p []byte) (n int, err error) {
return 0, errors.New("always error in writing")
}
func main() {
// You can specify a function to handle errors happens in logger.
// For example, you can count these errors and report them to team members by email.
global.HandleError = func(name string, err error) {
fmt.Printf("%s received an error: %+v\n", name, err)
}
// Let's log something to see what happen.
logger := logit.NewLogger(logit.Options().WithWriter(&uselessWriter{}))
logger.Info("See what happen?").Log()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rob_code/logit.git
git@gitee.com:rob_code/logit.git
rob_code
logit
logit
master

Search