jason c75afdc479 init | 1 gadu atpakaļ | |
---|---|---|
apis | 1 gadu atpakaļ | |
common.in | 1 gadu atpakaļ | |
conf | 1 gadu atpakaļ | |
consts | 1 gadu atpakaļ | |
docker | 1 gadu atpakaļ | |
errors | 1 gadu atpakaļ | |
impl | 1 gadu atpakaļ | |
model | 1 gadu atpakaļ | |
pb | 1 gadu atpakaļ | |
sh | 1 gadu atpakaļ | |
utils | 1 gadu atpakaļ | |
CHANGELOG.md | 1 gadu atpakaļ | |
Dockerfile.in | 1 gadu atpakaļ | |
Makefile | 1 gadu atpakaļ | |
README.md | 1 gadu atpakaļ | |
VERSION | 1 gadu atpakaļ | |
app.spec.in | 1 gadu atpakaļ | |
confbuild.sh | 1 gadu atpakaļ | |
go.mod | 1 gadu atpakaļ | |
go.sum | 1 gadu atpakaļ | |
imagebuild.sh | 1 gadu atpakaļ | |
main.go | 1 gadu atpakaļ | |
nohup.out | 1 gadu atpakaļ | |
rpmbuild.sh | 1 gadu atpakaļ |
本工程是微服务的demo。
# 取出共有第三方包工程,其中 /path/to 需要自己指定
# *** 如果其它工程做了软链接,则不需重复以下三步 ***
mkdir -P /path/to/repository/commons
cd /path/to/repository/commons
git clone http://gitlab.chejinjia.cn/repository/commons/golangpkgs.git
# 建立业务工程,并关联golangpkgs
mkdir -p /path/to/repository/projects/src
export GOPATH=/path/to/repository/projects
cd /path/to/repository/projects/src
ln -s /path/to/repository/commons/golangpkgs/vendor/ . # 如果其它工程做了软链接,则忽略此行
git clone git@gitlab.chejinjia.cn:repository/your_project.git # 本工程的链接
go build
...
1. 在要打印日志的包目录下,拷贝一份logger.go,并修改logger所属包名:
./impl/arith
└── logger.go
./common.in/task
└── logger.go
2. 在main.go
中添加如下代码:
// 通用logger
commonLogger := logger.InitLogger(runmode, fmt.Sprintf("logs/%s.log", appname),
maxSize, maxBackups, maxAge, disableStacktrace)
// 单独设置
accessLogger := logger.NewInfoLogger(runmode, fmt.Sprintf("logs/%s-access.log", appname),
maxSize, maxBackups, maxAge)
// 设置需要使用logger的地方
// common日志
arith.SetLogger(commonLogger)
// access日志
task.SetLogger(accessLogger)
l.Error("业务",
zap.String("操作", "操作名称"),
zap.String("参数或字段", "参数列表以及值"),
zap.String("error", err.Error()))
l.Error("mysql",
zap.String("sql", "SELECT from c_device"), // 操作+表名
zap.String("fields", utils.MarshalJsonString(field1, value1, field2, value2)),
zap.String("error", err.Error()))
l.Error("redis",
zap.String("cmd", "SETEX"), // 命令
zap.String("args", utils.MarshalJsonString(key, seconds, value)),
zap.String("error", err.Error()))
l.Error("rpc",
zap.String("call", "Arith.Add"), // 注册名.方法名
zap.String("args", utils.MarshalJsonString(req)),
zap.String("error", err.Error()))
l.Error("func",
zap.String("call", "Add"), // 函数名
zap.String("args", utils.MarshalJsonString(arg1, arg2, arg3)),
zap.String("error", err.Error()))