From 92508bcc0aef8bc34489af7ccbf3b625d1563fb9 Mon Sep 17 00:00:00 2001 From: Tlincy Date: Thu, 23 Apr 2020 09:35:51 +0800 Subject: [PATCH] Update LogUtils.cpp: use switch ... case to replace if ... else Signed-off-by: Tlincy <540549770@qq.com> --- core/src/utils/LogUtil.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/utils/LogUtil.cpp b/core/src/utils/LogUtil.cpp index 7c3a35f5..e94e8a8a 100644 --- a/core/src/utils/LogUtil.cpp +++ b/core/src/utils/LogUtil.cpp @@ -54,27 +54,31 @@ RolloutHandler(const char* filename, std::size_t size, el::Level level) { int ret; std::string m(std::string(dir) + "/" + s); s = m; - if (level == el::Level::Global) { - s.append("." + std::to_string(++global_idx)); - ret = rename(m.c_str(), s.c_str()); - } else if (level == el::Level::Debug) { + switch(level){ + case el::Level::Debug: s.append("." + std::to_string(++debug_idx)); ret = rename(m.c_str(), s.c_str()); - } else if (level == el::Level::Warning) { + break; + case el::Level::Warning: s.append("." + std::to_string(++warning_idx)); ret = rename(m.c_str(), s.c_str()); - } else if (level == el::Level::Trace) { + break; + case el::Level::Trace: s.append("." + std::to_string(++trace_idx)); ret = rename(m.c_str(), s.c_str()); - } else if (level == el::Level::Error) { + break; + case el::Level::Error: s.append("." + std::to_string(++error_idx)); ret = rename(m.c_str(), s.c_str()); - } else if (level == el::Level::Fatal) { + break; + case el::Level::Fatal: s.append("." + std::to_string(++fatal_idx)); ret = rename(m.c_str(), s.c_str()); - } else { + break; + default: s.append("." + std::to_string(++global_idx)); ret = rename(m.c_str(), s.c_str()); + break; } } -- GitLab