glog icon indicating copy to clipboard operation
glog copied to clipboard

Allow the user to prefix our flags' names

Open gurjeet opened this issue 3 years ago • 2 comments

This problem 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.

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.

gurjeet avatar Feb 10 '22 22:02 gurjeet

You are welcome to fork the code, but as it says in the README:

"The master copy of the source lives inside Google, not here. The code in this repo is for export only and is not itself under development. Feature requests will be ignored."

robpike avatar Feb 10 '22 22:02 robpike

Thanks for pointing that out @robpike. I did read that warning, but I created this issue/PR since it's arguably a bugfix, and not a new feature request.

As suggested in the README, I have subscribed to and sent an email to the golang-nuts mailing list, but for some reason my email has not shown up in the public, yet. Perhaps my email is stuck in moderation queue.

In any case, I'll keep trying to engage the community on the mailing list, and keep this issue for posterity.

gurjeet avatar Feb 10 '22 23:02 gurjeet