From 8e37256f24e75bebed9ae749a6e344b2f4423362 Mon Sep 17 00:00:00 2001 From: Matt Butrovich Date: Tue, 31 Jul 2018 10:31:30 -0400 Subject: [PATCH] Removed CRLF line separators on logger files and add .gitattributes file. (#41) --- .gitattributes | 19 +++ src/common/logger.cpp | 208 +++++++++++++------------- src/include/common/logger.h | 284 ++++++++++++++++++------------------ 3 files changed, 265 insertions(+), 246 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..540027a4ea --- /dev/null +++ b/.gitattributes @@ -0,0 +1,19 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +*.c text +*.cc text +*.cpp text +*.h text +*.txt text +*.md text +*.yml text +*.sh text +*.cmake text +*.py text + +# Denote all files that are truly binary and should not be modified. +*.png binary +*.jpg binary \ No newline at end of file diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 2e4d8eaf26..5751ffea42 100755 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -1,105 +1,105 @@ -//===----------------------------------------------------------------------===// -// -// Peloton -// -// logger.cpp -// -// Identification: src/common/logger.cpp -// -// Copyright (c) 2015-16, Carnegie Mellon University Database Group -// -//===----------------------------------------------------------------------===// - -#include "common/logger.h" - -// #include "common/internal_types.h" -#include "easylogging++/easylogging++.h" -// #include "settings/settings_manager.h" - -// Initialize for Easylogging++ library -INITIALIZE_EASYLOGGINGPP - -namespace terrier { - -/* @brief Initialize Peloton logger to set Easylogging++ according to settings - */ -void Logger::InitializeLogger() { - el::Configurations logger_conf; - logger_conf.setToDefault(); - - // log flush threshold - logger_conf.set(el::Level::Global, - el::ConfigurationType::LogFlushThreshold, - LOG_FLUSH_THERESHOLD); - - // log format setting - logger_conf.set(el::Level::Global, - el::ConfigurationType::Format, - LOG_FORMAT); - - /* - * ToDo: Need settings_manager and internal_types to set log level on booting - * - - // standard output setting - logger_conf.set(el::Level::Global, - el::ConfigurationType::ToStandardOutput, - settings::SettingsManager::GetString( - settings::SettingId::log_to_standard_output)); - - // file output setting - logger_conf.set(el::Level::Global, - el::ConfigurationType::ToFile, - settings::SettingsManager::GetString( - settings::SettingId::log_to_file)); - - if (settings::SettingsManager::GetBool(settings::SettingId::log_to_file)) { - // file path setting - logger_conf.set(el::Level::Global, - el::ConfigurationType::Filename, - settings::SettingsManager::GetString( - settings::SettingId::log_file_path)); - } - - // log level setting for Easylogging++ by log_level setting parameter in Peloton - auto log_level = StringToPelotonLogLevel( - settings::SettingsManager::GetString(settings::SettingId::log_level)); +//===----------------------------------------------------------------------===// +// +// Peloton +// +// logger.cpp +// +// Identification: src/common/logger.cpp +// +// Copyright (c) 2015-16, Carnegie Mellon University Database Group +// +//===----------------------------------------------------------------------===// + +#include "common/logger.h" + +// #include "common/internal_types.h" +#include "easylogging++/easylogging++.h" +// #include "settings/settings_manager.h" + +// Initialize for Easylogging++ library +INITIALIZE_EASYLOGGINGPP + +namespace terrier { + +/* @brief Initialize Peloton logger to set Easylogging++ according to settings + */ +void Logger::InitializeLogger() { + el::Configurations logger_conf; + logger_conf.setToDefault(); + + // log flush threshold + logger_conf.set(el::Level::Global, + el::ConfigurationType::LogFlushThreshold, + LOG_FLUSH_THERESHOLD); + + // log format setting + logger_conf.set(el::Level::Global, + el::ConfigurationType::Format, + LOG_FORMAT); + + /* + * ToDo: Need settings_manager and internal_types to set log level on booting + * + + // standard output setting + logger_conf.set(el::Level::Global, + el::ConfigurationType::ToStandardOutput, + settings::SettingsManager::GetString( + settings::SettingId::log_to_standard_output)); + + // file output setting + logger_conf.set(el::Level::Global, + el::ConfigurationType::ToFile, + settings::SettingsManager::GetString( + settings::SettingId::log_to_file)); + + if (settings::SettingsManager::GetBool(settings::SettingId::log_to_file)) { + // file path setting + logger_conf.set(el::Level::Global, + el::ConfigurationType::Filename, + settings::SettingsManager::GetString( + settings::SettingId::log_file_path)); + } + + // log level setting for Easylogging++ by log_level setting parameter in Peloton + auto log_level = StringToPelotonLogLevel( + settings::SettingsManager::GetString(settings::SettingId::log_level)); switch (log_level) { - case PelotonLogLevel::ERROR: - logger_conf.set(el::Level::Warning, - el::ConfigurationType::Enabled, - "false"); - // no break - case PelotonLogLevel::WARN: - logger_conf.set(el::Level::Info, - el::ConfigurationType::Enabled, - "false"); - // no break - case PelotonLogLevel::INFO: - logger_conf.set(el::Level::Debug, - el::ConfigurationType::Enabled, - "false"); - // no break - case PelotonLogLevel::DEBUG: - logger_conf.set(el::Level::Trace, - el::ConfigurationType::Enabled, - "false"); - // no break - case PelotonLogLevel::TRACE: - // enable all log levels - break; - default: { - throw Exception(StringUtil::Format( - "Invalid Peloton log level appears '%s'", - PelotonLogLevelToString(log_level).c_str())); - } - } - */ - - // apply the logger configuration - el::Loggers::reconfigureLogger(LOGGER_NAME, logger_conf); -} - -} - - + case PelotonLogLevel::ERROR: + logger_conf.set(el::Level::Warning, + el::ConfigurationType::Enabled, + "false"); + // no break + case PelotonLogLevel::WARN: + logger_conf.set(el::Level::Info, + el::ConfigurationType::Enabled, + "false"); + // no break + case PelotonLogLevel::INFO: + logger_conf.set(el::Level::Debug, + el::ConfigurationType::Enabled, + "false"); + // no break + case PelotonLogLevel::DEBUG: + logger_conf.set(el::Level::Trace, + el::ConfigurationType::Enabled, + "false"); + // no break + case PelotonLogLevel::TRACE: + // enable all log levels + break; + default: { + throw Exception(StringUtil::Format( + "Invalid Peloton log level appears '%s'", + PelotonLogLevelToString(log_level).c_str())); + } + } + */ + + // apply the logger configuration + el::Loggers::reconfigureLogger(LOGGER_NAME, logger_conf); +} + +} + + diff --git a/src/include/common/logger.h b/src/include/common/logger.h index e695364d78..eb08a9d4a9 100644 --- a/src/include/common/logger.h +++ b/src/include/common/logger.h @@ -1,142 +1,142 @@ -/*************************************************************************** - * Copyright (C) 2008 by H-Store Project * - * Brown University * - * Massachusetts Institute of Technology * - * Yale University * - * * - * This software may be modified and distributed under the terms * - * of the MIT license. See the LICENSE file for details. * - * * - ***************************************************************************/ - -#ifndef HSTOREDEBUGLOG_H -#define HSTOREDEBUGLOG_H - -/** - * Debug logging functions for EE. Unlike the performance counters, - * these are just StringUtil::Format() turned on/off by LOG_LEVEL compile option. - * The main concern here is not to add any overhead on runtime performance - * when the logging is turned off. Use LOG_XXX_ENABLED macros defined here to - * eliminate all instructions in the final binary. - * @author Hideaki - */ - -/** - * To be more useful debugging, added command arguments for the server to control - * log levels on runtime. Note that the log level disabled by compile option - * doesn't work on runtime even if enables the log level on runtime. - * e.g.) compiled with -DLOG_LEVEL=LOG_LEVEL_DEBUG - * => ./terrier -log_level=TRACE => LOG_TRACE() is never called - */ - -#include "easylogging++/easylogging++.h" -#include "util/string_util.h" - -#include -#include - -// Fix for PRId64 (See https://stackoverflow.com/a/18719205) -#if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS) -#define __STDC_FORMAT_MACROS 1 // Not sure where to put this -#endif -#include - -// Note that __PELOTONFILE__ is a special pre-processor macro that we -// generate for shorter path names using CMake. - -// Log levels for compile option. -#define LOG_LEVEL_OFF 1000 -#define LOG_LEVEL_ERROR 500 -#define LOG_LEVEL_WARN 400 -#define LOG_LEVEL_INFO 300 -#define LOG_LEVEL_DEBUG 200 -#define LOG_LEVEL_TRACE 100 -#define LOG_LEVEL_ALL 0 - -// Compile Option -#ifndef LOG_LEVEL -// TODO : any way to use pragma message in GCC? -//#pragma message("Warning: LOG_LEVEL compile option was not explicitly -// given.") -#ifndef NDEBUG -// In debug mode, all log macros are usable. -#define LOG_LEVEL LOG_LEVEL_ALL -#else -#define LOG_LEVEL LOG_LEVEL_INFO -#endif -#endif - -// For compilers which do not support __FUNCTION__ -#if !defined(__FUNCTION__) && !defined(__GNUC__) -#define __FUNCTION__ "" -#endif - -// Two convenient macros for debugging -// 1. Logging macros. -// 2. LOG_XXX_ENABLED macros. Use these to "eliminate" all the debug blocks from -// release binary. -#ifdef LOG_ERROR_ENABLED -#undef LOG_ERROR_ENABLED -#endif -#if LOG_LEVEL <= LOG_LEVEL_ERROR -#define LOG_ERROR_ENABLED -#define LOG_ERROR(...) CLOG(ERROR, LOGGER_NAME) << terrier::StringUtil::Format(__VA_ARGS__); -#else -#define LOG_ERROR(...) ((void)0) -#endif - -#ifdef LOG_WARN_ENABLED -#undef LOG_WARN_ENABLED -#endif -#if LOG_LEVEL <= LOG_LEVEL_WARN -#define LOG_WARN_ENABLED -#define LOG_WARN(...) CLOG(WARNING, LOGGER_NAME) << terrier::StringUtil::Format(__VA_ARGS__); -#else -#define LOG_WARN(...) ((void)0) -#endif - -#ifdef LOG_INFO_ENABLED -#undef LOG_INFO_ENABLED -#endif -#if LOG_LEVEL <= LOG_LEVEL_INFO -#define LOG_INFO_ENABLED -#define LOG_INFO(...) CLOG(INFO, LOGGER_NAME) << terrier::StringUtil::Format(__VA_ARGS__); -#else -#define LOG_INFO(...) ((void)0) -#endif - -#ifdef LOG_DEBUG_ENABLED -#undef LOG_DEBUG_ENABLED -#endif -#if LOG_LEVEL <= LOG_LEVEL_DEBUG -#define LOG_DEBUG_ENABLED -#define LOG_DEBUG(...) CLOG(DEBUG, LOGGER_NAME) << terrier::StringUtil::Format(__VA_ARGS__); -#else -#define LOG_DEBUG(...) ((void)0) -#endif - -#ifdef LOG_TRACE_ENABLED -#undef LOG_TRACE_ENABLED -#endif -#if LOG_LEVEL <= LOG_LEVEL_TRACE -#define LOG_TRACE_ENABLED -#define LOG_TRACE(...) CLOG(TRACE, LOGGER_NAME) << terrier::StringUtil::Format(__VA_ARGS__); -#else -#define LOG_TRACE(...) ((void)0) -#endif - -namespace terrier { - -// Macros for logger initialization -#define LOGGER_NAME "terrier" -#define LOG_FORMAT "%datetime [%file:%line] %level - %msg" -#define LOG_FLUSH_THERESHOLD "1" - -class Logger { - public: - static void InitializeLogger(); -}; - -} // namespace terrier - -#endif +/*************************************************************************** + * Copyright (C) 2008 by H-Store Project * + * Brown University * + * Massachusetts Institute of Technology * + * Yale University * + * * + * This software may be modified and distributed under the terms * + * of the MIT license. See the LICENSE file for details. * + * * + ***************************************************************************/ + +#ifndef HSTOREDEBUGLOG_H +#define HSTOREDEBUGLOG_H + +/** + * Debug logging functions for EE. Unlike the performance counters, + * these are just StringUtil::Format() turned on/off by LOG_LEVEL compile option. + * The main concern here is not to add any overhead on runtime performance + * when the logging is turned off. Use LOG_XXX_ENABLED macros defined here to + * eliminate all instructions in the final binary. + * @author Hideaki + */ + +/** + * To be more useful debugging, added command arguments for the server to control + * log levels on runtime. Note that the log level disabled by compile option + * doesn't work on runtime even if enables the log level on runtime. + * e.g.) compiled with -DLOG_LEVEL=LOG_LEVEL_DEBUG + * => ./terrier -log_level=TRACE => LOG_TRACE() is never called + */ + +#include "easylogging++/easylogging++.h" +#include "util/string_util.h" + +#include +#include + +// Fix for PRId64 (See https://stackoverflow.com/a/18719205) +#if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS) +#define __STDC_FORMAT_MACROS 1 // Not sure where to put this +#endif +#include + +// Note that __PELOTONFILE__ is a special pre-processor macro that we +// generate for shorter path names using CMake. + +// Log levels for compile option. +#define LOG_LEVEL_OFF 1000 +#define LOG_LEVEL_ERROR 500 +#define LOG_LEVEL_WARN 400 +#define LOG_LEVEL_INFO 300 +#define LOG_LEVEL_DEBUG 200 +#define LOG_LEVEL_TRACE 100 +#define LOG_LEVEL_ALL 0 + +// Compile Option +#ifndef LOG_LEVEL +// TODO : any way to use pragma message in GCC? +//#pragma message("Warning: LOG_LEVEL compile option was not explicitly +// given.") +#ifndef NDEBUG +// In debug mode, all log macros are usable. +#define LOG_LEVEL LOG_LEVEL_ALL +#else +#define LOG_LEVEL LOG_LEVEL_INFO +#endif +#endif + +// For compilers which do not support __FUNCTION__ +#if !defined(__FUNCTION__) && !defined(__GNUC__) +#define __FUNCTION__ "" +#endif + +// Two convenient macros for debugging +// 1. Logging macros. +// 2. LOG_XXX_ENABLED macros. Use these to "eliminate" all the debug blocks from +// release binary. +#ifdef LOG_ERROR_ENABLED +#undef LOG_ERROR_ENABLED +#endif +#if LOG_LEVEL <= LOG_LEVEL_ERROR +#define LOG_ERROR_ENABLED +#define LOG_ERROR(...) CLOG(ERROR, LOGGER_NAME) << terrier::StringUtil::Format(__VA_ARGS__); +#else +#define LOG_ERROR(...) ((void)0) +#endif + +#ifdef LOG_WARN_ENABLED +#undef LOG_WARN_ENABLED +#endif +#if LOG_LEVEL <= LOG_LEVEL_WARN +#define LOG_WARN_ENABLED +#define LOG_WARN(...) CLOG(WARNING, LOGGER_NAME) << terrier::StringUtil::Format(__VA_ARGS__); +#else +#define LOG_WARN(...) ((void)0) +#endif + +#ifdef LOG_INFO_ENABLED +#undef LOG_INFO_ENABLED +#endif +#if LOG_LEVEL <= LOG_LEVEL_INFO +#define LOG_INFO_ENABLED +#define LOG_INFO(...) CLOG(INFO, LOGGER_NAME) << terrier::StringUtil::Format(__VA_ARGS__); +#else +#define LOG_INFO(...) ((void)0) +#endif + +#ifdef LOG_DEBUG_ENABLED +#undef LOG_DEBUG_ENABLED +#endif +#if LOG_LEVEL <= LOG_LEVEL_DEBUG +#define LOG_DEBUG_ENABLED +#define LOG_DEBUG(...) CLOG(DEBUG, LOGGER_NAME) << terrier::StringUtil::Format(__VA_ARGS__); +#else +#define LOG_DEBUG(...) ((void)0) +#endif + +#ifdef LOG_TRACE_ENABLED +#undef LOG_TRACE_ENABLED +#endif +#if LOG_LEVEL <= LOG_LEVEL_TRACE +#define LOG_TRACE_ENABLED +#define LOG_TRACE(...) CLOG(TRACE, LOGGER_NAME) << terrier::StringUtil::Format(__VA_ARGS__); +#else +#define LOG_TRACE(...) ((void)0) +#endif + +namespace terrier { + +// Macros for logger initialization +#define LOGGER_NAME "terrier" +#define LOG_FORMAT "%datetime [%file:%line] %level - %msg" +#define LOG_FLUSH_THERESHOLD "1" + +class Logger { + public: + static void InitializeLogger(); +}; + +} // namespace terrier + +#endif