Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#
# LASAM (aka lgar-c, CASAM) CMakeLists.txt
#

cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_C_COMPILER $ENV{CC})
Expand Down Expand Up @@ -69,13 +73,13 @@ ENDIF((NOT ${NGEN}) AND (NOT ${STANDALONE}))

if(STANDALONE)
add_executable(${exe_name} ./src/bmi_main_lgar.cxx ./src/bmi_lgar.cxx ./src/lgar.cxx ./src/soil_funcs.cxx
./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./src/Logger.cpp ./include/Logger.hpp
./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx
./giuh/giuh.h ./giuh/giuh.c)
target_link_libraries(${exe_name} PRIVATE m)
target_link_libraries(${exe_name} PRIVATE Boost::serialization)
elseif(UNITTEST)
add_executable(${exe_name} ./tests/main_unit_test_bmi.cxx ./src/bmi_lgar.cxx ./src/lgar.cxx ./src/soil_funcs.cxx
./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./src/Logger.cpp ./include/Logger.hpp ./giuh/giuh.h
./src/linked_list.cxx ./src/mem_funcs.cxx ./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.h
./giuh/giuh.c)
target_link_libraries(${exe_name} PRIVATE m)
target_link_libraries(${exe_name} PRIVATE Boost::serialization)
Expand All @@ -91,10 +95,10 @@ add_compile_definitions(BMI_ACTIVE)

if(WIN32)
add_library(lasambmi SHARED src/bmi_lgar.cxx src/lgar.cxx ./src/soil_funcs.cxx ./src/linked_list.cxx ./src/mem_funcs.cxx
./src/util_funcs.cxx ./src/aet.cxx ./src/Logger.cpp ./include/Logger.hpp ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
else()
add_library(lasambmi SHARED src/bmi_lgar.cxx src/lgar.cxx ./src/soil_funcs.cxx ./src/linked_list.cxx ./src/mem_funcs.cxx
./src/util_funcs.cxx ./src/aet.cxx ./src/Logger.cpp ./include/Logger.hpp ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
./src/util_funcs.cxx ./src/aet.cxx ./giuh/giuh.c include/all.hxx ./giuh/giuh.h)
endif()


Expand All @@ -106,6 +110,17 @@ set_target_properties(lasambmi PROPERTIES PUBLIC_HEADER ./include/bmi_lgar.hxx)

target_link_libraries(lasambmi PRIVATE Boost::serialization)

# --- EWTS (installed from nwm-ewts) ---
find_package(ewts CONFIG REQUIRED)

# Always use EWTS runtime logger for CPP
target_link_libraries(lasambmi PRIVATE ewts::ewts_cpp)

# Built with ngen bridge
target_link_libraries(lasambmi PRIVATE
"-Wl,--no-as-needed" ewts::ewts_ngen_bridge "-Wl,--as-needed")
target_compile_definitions(lasambmi PRIVATE EWTS_HAVE_NGEN_BRIDGE)

include(GNUInstallDirs)

install(TARGETS lasambmi
Expand Down
71 changes: 9 additions & 62 deletions include/Logger.hpp
Original file line number Diff line number Diff line change
@@ -1,66 +1,13 @@
#ifndef LOGGER_HPP
#define LOGGER_HPP
#ifndef LASAM_LOGGER_HPP
#define LASAM_LOGGER_HPP

#include <ctime>
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
#include <stdlib.h>
#include <string>
#include "ewts/logger.hpp"
#include "ewts/module_constants.hpp"

#define LOG Logger::Log
using ewts::EwtsInit;
using ewts::LogLevel;

enum class LogLevel {
NONE = 0,
DEBUG = 1,
INFO = 2,
WARNING = 3,
SEVERE = 4,
FATAL = 5,
};
// Provide the constant in the global namespace:
inline constexpr const char* EWTS_ID_LASAM = ewts::modules::EWTS_ID_LASAM;

/**
* Logger Class Used to Output Details of Current Application Flow
All methods and variables are static so instantiating an object is unnecessary.
*/
class Logger {
public:
// Methods
static void Log(LogLevel messageLevel, const char* message, ...);
static void Log(LogLevel messageLevel, std::string message);
static void Log(std::string message, LogLevel messageLevel = LogLevel::INFO);
static bool IsLoggingEnabled(void);
static LogLevel GetLogLevel(void);

private:
// Methods
static std::string CreateDateString(void);
static std::string CreateTimestamp(bool appendMS = true, bool iso = true);
static bool CreateDirectory(const std::string& path);
static std::string ConvertLogLevelToString(LogLevel level);
static LogLevel ConvertStringToLogLevel(const std::string& logLevel);
static bool DirectoryExists(const std::string& path);
static std::string GetLogFilePath(void);
static bool LogFileReady(bool appendMode=true);
static void SetLogFilePath(void);
static void SetLoggingFlag(void);
static void SetLogLevel(void);
static void SetLogModuleName(void);
static void SetLogPreferences(void);
static std::string ToUpper(const std::string& input);
static std::string TrimString(const std::string& str);

// Variables
// Declaring these static so they exist in the class without needing to instantiate it.
static bool loggerInitialized;
static std::string logFilePath;
static bool loggingEnabled;
static std::fstream logFile;
static LogLevel logLevel;
static std::string moduleName;

static std::shared_ptr<Logger> loggerInstance;
};

#endif
#endif /* LASAM_LOGGER_HPP */
Loading
Loading