diff --git a/userspace/libsinsp/logger.cpp b/userspace/libsinsp/logger.cpp index b8d8418d7a..919c939e34 100644 --- a/userspace/libsinsp/logger.cpp +++ b/userspace/libsinsp/logger.cpp @@ -36,15 +36,11 @@ const size_t ENCODE_LEN = sizeof(uint64_t); } // end namespace -sinsp_logger* sinsp_logger::s_logger = nullptr; +sinsp_logger sinsp_logger::s_logger; sinsp_logger* sinsp_logger::instance() { - if(s_logger == nullptr) - { - s_logger = new sinsp_logger(); - } - return s_logger; + return &s_logger; } const uint32_t sinsp_logger::OT_NONE = 0; diff --git a/userspace/libsinsp/logger.h b/userspace/libsinsp/logger.h index cd8a078ac3..250c7f0303 100644 --- a/userspace/libsinsp/logger.h +++ b/userspace/libsinsp/logger.h @@ -170,7 +170,7 @@ class SINSP_PUBLIC sinsp_logger sinsp_logger(); ~sinsp_logger(); - static sinsp_logger* s_logger; + static sinsp_logger s_logger; /** Disable copy constructor and assignment operator */ sinsp_logger(const sinsp_logger&) = delete; diff --git a/userspace/libsinsp/user.cpp b/userspace/libsinsp/user.cpp index 532764ac81..48303cc02b 100644 --- a/userspace/libsinsp/user.cpp +++ b/userspace/libsinsp/user.cpp @@ -302,7 +302,7 @@ scap_userinfo *sinsp_usergroup_manager::add_user(const std::string &container_id scap_userinfo *sinsp_usergroup_manager::add_host_user(uint32_t uid, uint32_t gid, std::string_view name, std::string_view home, std::string_view shell, bool notify) { libsinsp_logger()->format(sinsp_logger::SEV_DEBUG, - "adding host user: name: %s", name); + "adding host user: name: %.*s", static_cast(name.length()), name.data()); scap_userinfo *retval{nullptr}; if (name.data() != nullptr) @@ -434,7 +434,7 @@ scap_groupinfo *sinsp_usergroup_manager::add_group(const string &container_id, i scap_groupinfo *sinsp_usergroup_manager::add_host_group(uint32_t gid, std::string_view name, bool notify) { libsinsp_logger()->format(sinsp_logger::SEV_DEBUG, - "adding host group: name: %s", name); + "adding host group: name: %.*s", static_cast(name.length()), name.data()); scap_groupinfo *gr = nullptr; if (name.data())