From 891eddca3012900d9012eff7f8c44fd47b3e28e6 Mon Sep 17 00:00:00 2001 From: NigelWu95 Date: Sat, 11 Dec 2021 01:44:42 +0800 Subject: [PATCH] feat: add CUSTOM type to support custom log path set by log-path flag, conveniently saving the log file in custom path, for the logs persistence scene. Signed-off-by: NigelWu95 --- util/log.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/util/log.go b/util/log.go index b055cb7..22096aa 100644 --- a/util/log.go +++ b/util/log.go @@ -29,12 +29,14 @@ import ( const ( Blade = 1 Bin = 2 + Custom= 3 ) const BladeLog = "chaosblade.log" var ( Debug bool + LogPath string LogLevel string ) @@ -42,6 +44,10 @@ func AddDebugFlag() { flag.BoolVar(&Debug, "debug", false, "set debug mode") } +func AddLogPathFlag() { + flag.StringVar(&LogPath, "log-path", GetProgramPath(), "the directory path to save chaosblade.log.") +} + func AddLogLevelFlag() { flag.StringVar(&LogLevel, "log-level", "info", "level of logging wanted.") } @@ -127,6 +133,8 @@ func GetLogPath(programType int) (string, error) { binDir = GetProgramPath() case Bin: binDir = GetProgramParentPath() + case Custom: + binDir = LogPath default: binDir = GetProgramPath() }