1 Star 0 Fork 1

freely随意 / BaiduPCS-Go

forked from ttpc2008 / BaiduPCS-Go 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pcsverbose.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
konica 提交于 2018-05-03 16:34 . fix #153, 调整配置文件储存目录
// Package pcsverbose 调试包
package pcsverbose
import (
"fmt"
"io"
"os"
)
const (
// EnvVerbose 启用调试环境变量
EnvVerbose = "BAIDUPCS_GO_VERBOSE"
)
var (
// IsVerbose 是否调试
IsVerbose = os.Getenv(EnvVerbose) == "1"
// Outputs 输出
Outputs = []io.Writer{os.Stderr}
)
// PCSVerbose 调试
type PCSVerbose struct {
Module string
}
// New 根据module, 初始化PCSVerbose
func New(module string) *PCSVerbose {
return &PCSVerbose{
Module: module,
}
}
// Info 提示
func (pv *PCSVerbose) Info(l string) {
Verbosef("DEBUG: %s INFO: %s\n", pv.Module, l)
}
// Infof 提示, 格式输出
func (pv *PCSVerbose) Infof(format string, a ...interface{}) {
Verbosef("DEBUG: %s INFO: %s", pv.Module, fmt.Sprintf(format, a...))
}
// Warn 警告
func (pv *PCSVerbose) Warn(l string) {
Verbosef("DEBUG: %s WARN: %s\n", pv.Module, l)
}
// Warnf 警告, 格式输出
func (pv *PCSVerbose) Warnf(format string, a ...interface{}) {
Verbosef("DEBUG: %s WARN: %s", pv.Module, fmt.Sprintf(format, a...))
}
// Verbosef 调试格式输出
func Verbosef(format string, a ...interface{}) (n int, err error) {
if IsVerbose {
for _, Output := range Outputs {
n, err = fmt.Fprintf(Output, format, a...)
}
}
return
}
// Verboseln 调试输出一行
func Verboseln(a ...interface{}) (n int, err error) {
if IsVerbose {
for _, Output := range Outputs {
n, err = fmt.Fprintln(Output, a...)
}
}
return
}
1
https://gitee.com/freelysuiyi/BaiduPCS-Go.git
git@gitee.com:freelysuiyi/BaiduPCS-Go.git
freelysuiyi
BaiduPCS-Go
BaiduPCS-Go
v3.5.1

搜索帮助