命令行参数
在Easylogging++中可通过START_EASYLOGGINGPP(argc, argv)来完成命令行参数的设置,下面的表格列举了GitHub上给出的Easylogging++支持的命令行参数:
Argument | Description |
---|---|
-v |
Activates maximum verbosity |
--v=2 |
Activates verbosity upto verbose level 2 (valid range: 0-9) |
--verbose |
Activates maximum verbosity |
-vmodule=MODULE_NAME |
Activates verbosity for files starting with main to level 1, the rest of the files depend on logging flag AllowVerboseIfModuleNotSpecified Please see Logging Flags section above. Two modules can be separated by comma. Please note vmodules are last in order of precedence of checking arguments for verbose logging, e.g, if we have -v in application arguments before vmodules, vmodules will be ignored. |
--logging-flags=3 |
Sets logging flag. In example i.e, 3 , it sets logging flag toNewLineForContainer and AllowVerboseIfModuleNotSpecified . See logging flags section above for further details and values. See macros section to disable this function. |
--default-log-file=FILE |
Sets default log file for existing and future loggers. You may want to consider defining ELPP_NO_DEFAULT_LOG_FILE to prevent creation of default empty log file during pre-processing. See macros section to disable this function. |
对于上述命令行参数,有必要简要说明一下:
其中的 -v 、 --v 、 --verbose 、 -vmodule 都是用来设置 Verbose 详细日志的,而且这几个参数之间是有优先级顺序的,如下:-v 优先于 --verbose 优先于 --v 优先于 -vmodule。但是,在效果上 -v 和 --verbose 是一样的。请看下面的例子:
命令行参数例一:--v=2 -v ,在这里参数 --v=2 会被参数 -v 覆盖,因为 -v 优先级最高。
命令行参数例二:--verbose -vmodule=main=3 ,在这里参数 -vmodule=main=3 会被参数 --verbose 覆盖,因为 --verbose 优先于 -vmodule 。
命令行参数例三:-vmodule=main*=3 --v=5 -v --verbose ,在这里参数 -v 会覆盖其他所有的参数,因为 -v 优先级最高。
其中的 --logging-flags 是用来设置日志标记的,而且必须定义 ELPP_LOGGING_FLAGS_FROM_ARG 这个宏定义。
其中的 --default-log-file 是用来设置日志默认保存文件名的。如果没用这个命令行参数设置文件名,那么默认的文件名就是logs\\myeasylog.log 。另外,我们也可以用宏定义 ELPP_DEFAULT_LOG_FILE 来达到相同的效果。如:#defineELPP_DEFAULT_LOG_FILE "logs\\tem\\test.log" 。
下面的代码演示了设置命令参数--v=2,其最终效果是VLOG(3)将会被屏蔽: