diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index ac29728152..4fc16d3fe0 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -181,7 +181,6 @@ endif() # logging ###################################### set(ecal_logging_src - src/logging/ecal_file_resource.cpp src/logging/ecal_log.cpp src/logging/ecal_log_impl.cpp src/logging/ecal_log_impl.h diff --git a/ecal/core/src/logging/ecal_file_resource.cpp b/ecal/core/src/logging/ecal_file_resource.cpp deleted file mode 100644 index 3f969ba849..0000000000 --- a/ecal/core/src/logging/ecal_file_resource.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* ========================= eCAL LICENSE ================================= - * - * Copyright (C) 2016 - 2024 Continental Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ========================= eCAL LICENSE ================================= -*/ - -#include "ecal_file_resource.h" - -#include - -namespace eCAL -{ - namespace Logging - { - void FileDeleter::operator()(FILE* file) const - { - if (file) { - fclose(file); - } - } - - FileResource::FileResource() : m_file(nullptr) - { - } - - bool FileResource::fopen(const char* filename, const char* mode) - { - m_file.reset(std::fopen(filename, mode)); - - if (m_file == nullptr) - { - return false; - } - else - { - return true; - } - } - - void FileResource::fprintf(const char* format, ...) - { - va_list args; - va_start(args, format); - vfprintf(m_file.get(), format, args); - va_end(args); - } - - void FileResource::fflush() - { - std::fflush(m_file.get()); - } - - void FileResource::fclose() - { - m_file.reset(); - } - - bool FileResource::isOpen() const - { - return m_file != nullptr; - } - } -} diff --git a/ecal/core/src/logging/ecal_file_resource.h b/ecal/core/src/logging/ecal_file_resource.h deleted file mode 100644 index c41dddd54d..0000000000 --- a/ecal/core/src/logging/ecal_file_resource.h +++ /dev/null @@ -1,53 +0,0 @@ -/* ========================= eCAL LICENSE ================================= - * - * Copyright (C) 2016 - 2024 Continental Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ========================= eCAL LICENSE ================================= -*/ - -/** - * @brief eCAL file resource class for logging implementation -**/ - -#pragma once - -#include -#include - -namespace eCAL -{ - namespace Logging - { - // Custom deleter for FILE* - struct FileDeleter { - void operator()(FILE* file) const; - }; - - class FileResource { - public: - FileResource(); - - bool fopen(const char* filename, const char* mode); - bool isOpen() const; - void fclose(); - - void fprintf(const char* format, ...); - void fflush(); - - private: - std::unique_ptr m_file; - }; - } -} \ No newline at end of file diff --git a/ecal/core/src/logging/ecal_log_impl.cpp b/ecal/core/src/logging/ecal_log_impl.cpp index 120aae060f..b1a7bfa725 100644 --- a/ecal/core/src/logging/ecal_log_impl.cpp +++ b/ecal/core/src/logging/ecal_log_impl.cpp @@ -148,7 +148,8 @@ namespace eCAL { CLog::CLog(const Logging::SAttributes& attr_) : m_created(false), - m_attributes(attr_) + m_attributes(attr_), + m_logfile(nullptr) { } @@ -162,20 +163,19 @@ namespace eCAL // create log file if file logging is enabled if(m_attributes.file.enabled) { - bool file_opened = false; if (isDirectory(m_attributes.file.path)) { const std::string tstring = get_time_str(); m_logfile_name = m_attributes.file.path + tstring + "_" + m_attributes.unit_name + "_" + std::to_string(m_attributes.process_id) + ".log"; - file_opened = m_logfile.fopen(m_logfile_name.c_str(), "w"); + m_logfile = fopen(m_logfile_name.c_str(), "w"); } else { logWarningToConsole("Logging for file enabled, but specified path to log is not valid: " + m_attributes.file.path); } - if (!file_opened) + if (m_logfile == nullptr) { logWarningToConsole("Logging for file enabled, but file could not be created."); } @@ -218,7 +218,8 @@ namespace eCAL m_udp_logging_sender.reset(); - if(m_logfile.isOpen()) m_logfile.fclose(); + if(m_logfile != nullptr) fclose(m_logfile); + m_logfile = nullptr; m_created = false; } @@ -280,8 +281,8 @@ namespace eCAL if (log_to_file) { - m_logfile.fprintf("%s\n", m_log_message_stream.str().c_str()); - m_logfile.fflush(); + fprintf(m_logfile, "%s\n", m_log_message_stream.str().c_str()); + fflush(m_logfile); } } diff --git a/ecal/core/src/logging/ecal_log_impl.h b/ecal/core/src/logging/ecal_log_impl.h index 3af11c8614..1f7ef196d8 100644 --- a/ecal/core/src/logging/ecal_log_impl.h +++ b/ecal/core/src/logging/ecal_log_impl.h @@ -35,7 +35,6 @@ #include "attributes/logging_attributes.h" #include "ecal_global_accessors.h" -#include "ecal_file_resource.h" #include #include @@ -44,7 +43,6 @@ #include #include - namespace eCAL { class CLog @@ -143,7 +141,7 @@ namespace eCAL std::shared_ptr m_log_receiver; std::string m_logfile_name; - Logging::FileResource m_logfile; + FILE* m_logfile; Logging::SAttributes m_attributes; std::stringstream m_log_message_stream;