This problem of glog polluting users' options has been reported quite a few
times over the years; for
example, see it reported at golang-nuts mailing list [1], and cue lang
issue [2].

[1]: https://groups.google.com/g/golang-nuts/c/vj8ozVqemnQ
[2]: https://github.com/cue-lang/cue/issues/1199

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 either to control verbosity of
their code-execution, or to show the software version. It's notable that
all the complaints are regarding the `-v` flag, and none about the other
flags, since those other flags are unlikely be used by any other
developer.

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

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

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

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

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

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

5. The --help flag, correctly reports the changed/prefixed 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

```

Please also see sample code [3] that demonstrates the problem, and how
the patch fixes the problem.

[3]: https://github.com/gurjeet/glog_fix_test

Best regards,
--
Gurjeet Singh http://gurjeet.singh.im/

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABwTF4WrA4fEyffiN9MDweJiQss8Mcr-7f781yiUSup5cBgqQw%40mail.gmail.com.

Reply via email to