Test case to fix a bug in github.com/golang/glog

glog Library Pollutes Global Flags List

This problem has been reported quite a few times, over the years; see it reported at golang-nuts mailing list, and cue lang issue.

The problem is that, that glog package registers some flags in its init() function. The list of registered flags also includes the -v flag, which is usually used by developers to either control verbosity of their code-execution, or to show the software version. It's notable that all the compaints are regarding the -v flag, and none of the other flags, since those other ones are unlikely be used by any other developer.

The proposed fix allows the user of the glog library to change/prefix glog's flags' names, so that they will not conflict with any flags that they wish to use.

This approach to the problem has a few advantages, compared to other approaches like, disabling all the flags in glog.

.) The default behaviour of the glog library is unchanged. So the current users of the library will not be affected.

.) Any new users who wish to use the -v, or other glog-occupied flag, can do so at build time.

.) The new users can still use the glog features/flags, albeit with a prefix.

.) We are not enforcing some specific prefix, which may also conflict.

.) The --help flag, correctly reports the changed/prefixd flag names.

$ ./main --help
Usage of ./main:

  ... other glog: prefixed flags ...

  -glog:v value
        log level for V logs
  -glog:vmodule value
        comma-separated list of pattern=N settings for file-filtered logging
  -v value
        Emit verbose execution progress

Steps to Reproduce

$ git clone https://github.com/gurjeet/glog_fix_test

$ cd glog_fix_test

$ go build -o main && ./main
./main flag redefined: v
panic: ./main flag redefined: v
... stack trace follows ...

Steps to Test the Fix

# Inside the same directory, clone the glog repo
$ git clone https://github.com/golang/glog.git
$ pushd glog

# Switch to the repo and branch that has the fix
$ git remote add gurjeet https://github.com/gurjeet/glog
$ git fetch --all
$ git checkout option_to_not_pollute_flags
# Alternatively, apply the patch included in this repository
#$ patch -p1 < ../bugfix.patch

$ popd

# Tell the compiler to use our local/pathced version of glog
$ go mod edit -replace=github.com/golang/glog=./glog

# Ask the linker to assign a value to the global variable FlagPrefix
$ go build -o main -ldflags "-X github.com/golang/glog.FlagPrefix=glog:"
$ ./main -glog:logtostderr -glog:v 1 -v somevalue

I0210 11:17:28.096799   72018 main.go:34] Hello from V(1).Info()

# Ask the linker to assign a different value to the global variable FlagPrefix
$ go build -o main -ldflags "-X github.com/golang/glog.FlagPrefix=abc"
$ ./main -abclogtostderr -abcv 1 -v somevalue
Similar Resources

Golang logging library

Golang logging library

Golang logging library Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging ba

Dec 27, 2022

A feature-rich and easy to use logger for golang

A feature-rich and easy to use logger for golang

A feature-rich and easy to use logger for golang 🚀 Install 🌲 Common Logs lumber.Success() lumber.Info() lumber.Debug() lumber.Warning()

Dec 31, 2022

A system and resource monitoring tool written in Golang!

A system and resource monitoring tool written in Golang!

Grofer A clean and modern system and resource monitor written purely in golang using termui and gopsutil! Currently compatible with Linux only. Curren

Jan 8, 2023

Golang beautify data display for Humans

Golang beautify data display for Humans English 简体中文 Usage Examples package main import ( ffmt "gopkg.in/ffmt.v1" ) func main() { example() } typ

Dec 22, 2022

Logstash like, written in golang

gogstash Logstash like, written in golang Download gogstash from github check latest version Use docker image tsaikd/gogstash curl 'https://github.com

Dec 18, 2022

Open Source Supreme Monitor Based on GoLang

Open Source Supreme Monitor Based on GoLang A module built for personal use but ended up being worthy to have it open sourced.

Nov 4, 2022

Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content.

Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content.

Noodlog Summary Noodlog is a Golang JSON parametrized and highly configurable logging library. It allows you to: print go structs as JSON messages; pr

Oct 27, 2022

HTTP request logger for Golang

HTTP request logger for Golang

Horus 𓂀 Introduction Horus is a request logger and viewer for Go. It allows developers log and view http requests made to their web application. Inst

Dec 27, 2022

Example instrumentation of Golang Application with OpenTelemetry with supported configurations to export to Sentry.

Example instrumentation of Golang Application with OpenTelemetry with supported configurations to export to Sentry.

Sentry + Opentelemetry Go Example Requirements To run this example, you will need a kubernetes cluster. This example has been tried and tested on Mini

Oct 27, 2022
Used to test the log collection function.

Used to test the log collection function.

Nov 30, 2021
ProfileStatusSyncer - A tool to synchronize user profile status of Github and Netease CloudMusic

ProfileStatusSyncer A tool to synchronize user profile status of GitHub and Nete

Jul 20, 2022
Simple and blazing fast lockfree logging library for golang
Simple and blazing fast lockfree logging library for golang

glg is simple golang logging library Requirement Go 1.11 Installation go get github.com/kpango/glg Example package main import ( "net/http" "time"

Nov 28, 2022
Logging library for Golang

GLO Logging library for Golang Inspired by Monolog for PHP, severity levels are identical Install go get github.com/lajosbencz/glo Severity levels Deb

Sep 26, 2022
a golang log lib supports level and multi handlers

go-log a golang log lib supports level and multi handlers Use import "github.com/siddontang/go-log/log" //log with different level log.Info("hello wo

Dec 29, 2022
LogVoyage - logging SaaS written in GoLang
LogVoyage - logging SaaS written in GoLang

No longer maintained, sorry. Completely rewritten v2 is going to be released soon. Please follow http://github.com/logvoyage LogVoyage - fast and simp

Sep 26, 2022
An golang log lib, supports tracking and level, wrap by standard log lib

Logex An golang log lib, supports tracing and level, wrap by standard log lib How To Get shell go get gopkg.in/logex.v1 source code import "gopkg.in/

Nov 27, 2022
Utilities for slightly better logging in Go (Golang).

logutils logutils is a Go package that augments the standard library "log" package to make logging a bit more modern, without fragmenting the Go ecosy

Dec 16, 2022
Dead simple, super fast, zero allocation and modular logger for Golang

Onelog Onelog is a dead simple but very efficient JSON logger. It is one of the fastest JSON logger out there. Also, it is one of the logger with the

Sep 26, 2022
A Go (golang) package providing high-performance asynchronous logging, message filtering by severity and category, and multiple message targets.

ozzo-log Other languages 简体中文 Русский Description ozzo-log is a Go package providing enhanced logging support for Go programs. It has the following fe

Dec 17, 2022