Golang Glog 项目使用教程

Golang Glog 项目使用教程

glogLeveled execution logs for Go项目地址:https://gitcode.com/gh_mirrors/gl/glog

1. 项目的目录结构及介绍

Golang Glog 项目的目录结构如下:

glog/
├── LICENSE
├── README.md
├── glog.go
├── glog_bench_test.go
├── glog_context_test.go
├── glog_file.go
├── glog_file_linux.go
├── glog_file_nonwindows.go
├── glog_file_other.go
├── glog_file_posix.go
├── glog_file_windows.go
├── glog_flags.go
├── glog_test.go
├── glog_vmodule_test.go
├── go.mod
└── go.sum

目录结构介绍

  • LICENSE: 项目的许可证文件。
  • README.md: 项目的说明文档。
  • glog.go: 主文件,包含了日志记录的核心功能。
  • glog_bench_test.go: 性能测试文件。
  • glog_context_test.go: 上下文相关的测试文件。
  • glog_file.go: 文件相关的日志记录功能。
  • glog_file_linux.go: Linux 平台下的文件日志记录功能。
  • glog_file_nonwindows.go: 非 Windows 平台下的文件日志记录功能。
  • glog_file_other.go: 其他平台下的文件日志记录功能。
  • glog_file_posix.go: POSIX 标准下的文件日志记录功能。
  • glog_file_windows.go: Windows 平台下的文件日志记录功能。
  • glog_flags.go: 日志记录的标志配置。
  • glog_test.go: 测试文件。
  • glog_vmodule_test.go: V 模块相关的测试文件。
  • go.mod: Go 模块文件,定义了项目的依赖。
  • go.sum: Go 模块的校验和文件。

2. 项目的启动文件介绍

项目的启动文件是 glog.go,它包含了日志记录的核心功能。以下是 glog.go 文件的部分代码示例:

package glog

import (
	"flag"
	"fmt"
	"os"
	"path/filepath"
	"runtime"
	"strconv"
	"strings"
	"sync"
	"sync/atomic"
	"time"
)

// Initialize package-level variables.
var (
	logging = &loggingT{
		toStderr:       true,
		alsoToStderr:   false,
		verbosity:      V(0),
		stderrThreshold Severity = ErrorLog,
		traceLocation  = new(traceLocationT),
	}
)

// Info logs a message at the info log level.
func Info(args ...interface{}) {
	logging.print(infoLog, args...)
}

// Error logs a message at the error log level.
func Error(args ...interface{}) {
	logging.print(errorLog, args...)
}

// Fatal logs a message at the fatal log level and then exits.
func Fatal(args ...interface{}) {
	logging.print(fatalLog, args...)
	os.Exit(1)
}

启动文件介绍

  • glog.go 文件定义了日志记录的核心功能,包括 InfoErrorFatal 等日志级别的记录方法。
  • 通过 logging 变量初始化日志记录的配置,如输出到标准错误、详细级别等。
  • 提供了多种日志记录方法,如 InfoErrorFatal,分别用于记录不同级别的日志信息。

3. 项目的配置文件介绍

Golang Glog 项目没有显式的配置文件,但可以通过命令行标志进行配置。以下是一些常用的配置标志:

常用配置标志

  • -logtostderr: 将日志输出到标准错误而不是文件。
  • -alsologtostderr: 同时将日志输出到标准错误和文件。
  • -v: 设置日志的详细级别。
  • -vmodule: 设置特定文件的日志详细级别。

配置示例

go run main.go

glogLeveled execution logs for Go项目地址:https://gitcode.com/gh_mirrors/gl/glog

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梅沁维

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值