forked from E3SM-Project/E3SM
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified Ome logging code and documentation per PR reviews.
* applied LLVM-coding style * removed of accepting OMEGA_LOG_FILEPATH user macro * revised ctest for logging to capture PASS/FAIL properly * updated userGuide and devGuide
- Loading branch information
Showing
16 changed files
with
410 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
components/omega/src/drivers/drvdummy.cpp → components/omega/src/drivers/DrvDummy.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
// OCN dummy driver | ||
|
||
#include "logging.h" | ||
#include "Logging.h" | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
void dummy(int argc, char **argv); | ||
|
||
int main(int argc, char **argv) { | ||
|
||
cout << endl << "Starting driver..." << endl; | ||
std::cout << std::endl << "Starting driver..." << std::endl; | ||
|
||
dummy(argc, argv); | ||
|
||
cout << "Stopped driver." << endl; | ||
std::cout << "Stopped driver." << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef OMEGA_LOG_FORMATTERS_H | ||
#define OMEGA_LOG_FORMATTERS_H | ||
//===-- infra/LogFormatters.h - Omega specific log formatters --*- C++ -*-===// | ||
// | ||
/// \file | ||
/// \brief Defines spdlog custom formatters | ||
/// | ||
/// This header defines custom formatters for Omega logging. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "DataTypes.h" | ||
#include <spdlog/spdlog.h> | ||
|
||
template <> | ||
struct fmt::formatter<OMEGA::ArrayHost1DReal> : fmt::formatter<std::string> { | ||
auto format(OMEGA::ArrayHost1DReal my, format_context &ctx) | ||
-> decltype(ctx.out()) { | ||
#ifdef OMEGA_DEBUG | ||
return fmt::format_to( | ||
ctx.out(), "[data type of '{}' is ArrayHost1DReal.]", my.label()); | ||
#else | ||
return fmt::format_to(ctx.out(), "[data type of '' is ArrayHost2DReal.]"); | ||
#endif | ||
} | ||
}; | ||
|
||
template <> | ||
struct fmt::formatter<OMEGA::ArrayHost2DReal> : fmt::formatter<std::string> { | ||
auto format(OMEGA::ArrayHost2DReal my, format_context &ctx) | ||
-> decltype(ctx.out()) { | ||
#ifdef OMEGA_DEBUG | ||
return fmt::format_to( | ||
ctx.out(), "[data type of '{}' is ArrayHost2DReal.]", my.label()); | ||
#else | ||
return fmt::format_to(ctx.out(), "[data type of '' is ArrayHost2DReal.]"); | ||
#endif | ||
} | ||
}; | ||
|
||
#endif // OMEGA_LOG_FORMATTERS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//===-- infra/Logging.cpp - Implements Omega Logging functions --*- C++ -*-===// | ||
// | ||
/// \file | ||
/// \brief implements Omega logging functions | ||
/// | ||
/// This implements Omega logging initialization. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "Logging.h" | ||
#include <spdlog/sinks/basic_file_sink.h> | ||
|
||
namespace OMEGA { | ||
|
||
void initLogging(std::shared_ptr<spdlog::logger> Logger) { | ||
|
||
try { | ||
Logger->flush_on(spdlog::level::warn); | ||
spdlog::set_default_logger(Logger); | ||
|
||
} catch (spdlog::spdlog_ex const &Ex) { | ||
std::cout << "Log init failed: " << Ex.what() << std::endl; | ||
} | ||
} | ||
|
||
void initLogging(std::string const &LogFilePath) { | ||
auto Logger = spdlog::basic_logger_mt("*", LogFilePath); | ||
initLogging(Logger); | ||
} | ||
|
||
} // namespace OMEGA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#ifndef OMEGA_LOG_H | ||
#define OMEGA_LOG_H | ||
//===-- infra/Logging.h - logging macros and custom formatters --*- C++ -*-===// | ||
// | ||
/// \file | ||
/// \brief Defines logging macros and spdlog custom formatters | ||
/// | ||
/// This header defines macros for logging. In addition, it includes | ||
/// Omega-specific log formatters. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "LogFormatters.h" | ||
#include <spdlog/spdlog.h> | ||
|
||
namespace OMEGA { | ||
|
||
void initLogging(std::shared_ptr<spdlog::logger> Logger); | ||
void initLogging(std::string const &LogFilePath); | ||
} // namespace OMEGA | ||
|
||
#define LOG_LEVEL_TRACE SPDLOG_LEVEL_TRACE | ||
#define LOG_LEVEL_DEBUG SPDLOG_LEVEL_DEBUG | ||
#define LOG_LEVEL_INFO SPDLOG_LEVEL_INFO | ||
#define LOG_LEVEL_WARN SPDLOG_LEVEL_WARN | ||
#define LOG_LEVEL_ERROR SPDLOG_LEVEL_ERROR | ||
#define LOG_LEVEL_CRITICAL SPDLOG_LEVEL_CRITICAL | ||
#define LOG_LEVEL_OFF SPDLOG_LEVEL_OFF | ||
|
||
#if !defined(LOG_ACTIVE_LEVEL) | ||
#define LOG_ACTIVE_LEVEL LOG_LEVEL_INFO | ||
#endif | ||
|
||
#if defined(LOG_UNBUFFERED_LOGGING) | ||
#define _LOG_FLUSH(logger) logger->flush() | ||
#else | ||
#define _LOG_FLUSH(logger) (void)0 | ||
#endif | ||
|
||
#if LOG_ACTIVE_LEVEL <= LOG_LEVEL_TRACE | ||
#define LOGGER_TRACE(logger, ...) \ | ||
SPDLOG_LOGGER_TRACE(logger, __VA_ARGS__); \ | ||
_LOG_FLUSH(logger) | ||
#define LOG_TRACE(...) LOGGER_TRACE(spdlog::default_logger(), __VA_ARGS__) | ||
#else | ||
#define LOGGER_TRACE(logger, ...) (void)0 | ||
#define LOG_TRACE(...) (void)0 | ||
#endif | ||
|
||
#if LOG_ACTIVE_LEVEL <= LOG_LEVEL_DEBUG | ||
#define LOGGER_DEBUG(logger, ...) \ | ||
SPDLOG_LOGGER_DEBUG(logger, __VA_ARGS__); \ | ||
_LOG_FLUSH(logger) | ||
#define LOG_DEBUG(...) LOGGER_DEBUG(spdlog::default_logger(), __VA_ARGS__) | ||
#else | ||
#define LOGGER_DEBUG(logger, ...) (void)0 | ||
#define LOG_DEBUG(...) (void)0 | ||
#endif | ||
|
||
#if LOG_ACTIVE_LEVEL <= LOG_LEVEL_INFO | ||
#define LOGGER_INFO(logger, ...) \ | ||
SPDLOG_LOGGER_INFO(logger, __VA_ARGS__); \ | ||
_LOG_FLUSH(logger) | ||
#define LOG_INFO(...) LOGGER_INFO(spdlog::default_logger(), __VA_ARGS__) | ||
#else | ||
#define LOGGER_INFO(logger, ...) (void)0 | ||
#define LOG_INFO(...) (void)0 | ||
#endif | ||
|
||
#if LOG_ACTIVE_LEVEL <= LOG_LEVEL_WARN | ||
#define LOGGER_WARN(logger, ...) \ | ||
SPDLOG_LOGGER_WARN(logger, __VA_ARGS__); \ | ||
_LOG_FLUSH(logger) | ||
#define LOG_WARN(...) LOGGER_WARN(spdlog::default_logger(), __VA_ARGS__) | ||
#else | ||
#define LOGGER_WARN(logger, ...) (void)0 | ||
#define LOG_WARN(...) (void)0 | ||
#endif | ||
|
||
#if LOG_ACTIVE_LEVEL <= LOG_LEVEL_ERROR | ||
#define LOGGER_ERROR(logger, ...) \ | ||
SPDLOG_LOGGER_ERROR(logger, __VA_ARGS__); \ | ||
_LOG_FLUSH(logger) | ||
#define LOG_ERROR(...) LOGGER_ERROR(spdlog::default_logger(), __VA_ARGS__) | ||
#else | ||
#define LOGGER_ERROR(logger, ...) (void)0 | ||
#define LOG_ERROR(...) (void)0 | ||
#endif | ||
|
||
#if LOG_ACTIVE_LEVEL <= LOG_LEVEL_CRITICAL | ||
#define LOGGER_CRITICAL(logger, ...) \ | ||
SPDLOG_LOGGER_CRITICAL(logger, __VA_ARGS__); \ | ||
_LOG_FLUSH(logger) | ||
#define LOG_CRITICAL(...) LOGGER_CRITICAL(spdlog::default_logger(), __VA_ARGS__) | ||
#else | ||
#define LOGGER_CRITICAL(logger, ...) (void)0 | ||
#define LOG_CRITICAL(...) (void)0 | ||
#endif | ||
|
||
#endif // OMEGA_LOG_H |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.