diff --git a/examples/filesystem/01_minimal/CMakeLists.txt b/examples/filesystem/01_minimal/CMakeLists.txt index 0a92a02..00c428f 100644 --- a/examples/filesystem/01_minimal/CMakeLists.txt +++ b/examples/filesystem/01_minimal/CMakeLists.txt @@ -19,6 +19,9 @@ add_clazy_check(${current_target} ${current_target_sources}) add_uncrustify_format(${current_target} ${current_target_sources}) add_pvs_check(${current_target}) +add_dependencies(${current_target} base) +add_dependencies(${current_target} filesystem) + # Qt5 # qt_translation(TARGET ${current_target} TS_DIR ${CMAKE_SOURCE_DIR}/l10n LANGUAGES ru_RU) target_include_directories(${current_target} PRIVATE ${CMAKE_SOURCE_DIR}/src) @@ -27,7 +30,7 @@ target_include_directories(${current_target} SYSTEM PUBLIC ${SPDLOG_INCLUDE_DIRS target_include_directories(${current_target} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) target_compile_options(${current_target} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") -target_link_libraries(${current_target} myx-filesystem_static) +target_link_libraries(${current_target} myx-filesystem) target_link_libraries(${current_target} Qt5::Core) # Имя выходного файла для цели diff --git a/examples/log/01_minimal/CMakeLists.txt b/examples/log/01_minimal/CMakeLists.txt index ec92ac0..6f313d7 100644 --- a/examples/log/01_minimal/CMakeLists.txt +++ b/examples/log/01_minimal/CMakeLists.txt @@ -19,13 +19,16 @@ add_clazy_check(${current_target} ${current_target_sources}) add_uncrustify_format(${current_target} ${current_target_sources}) add_pvs_check(${current_target}) +add_dependencies(${current_target} base) +add_dependencies(${current_target} log) + # Qt5 # qt_translation(TARGET ${current_target} TS_DIR ${CMAKE_SOURCE_DIR}/l10n LANGUAGES ru_RU) target_include_directories(${current_target} PRIVATE ${CMAKE_SOURCE_DIR}/src) target_include_directories(${current_target} SYSTEM PUBLIC ${FMT_INCLUDE_DIRS}) target_include_directories(${current_target} SYSTEM PUBLIC ${SPDLOG_INCLUDE_DIRS}) -target_link_libraries(${current_target} myx-log_static) +target_link_libraries(${current_target} myx-log) # Имя выходного файла для цели set_target_properties(${current_target} diff --git a/examples/log/01_minimal/minimal.cpp b/examples/log/01_minimal/minimal.cpp index 876e5e9..a51c557 100644 --- a/examples/log/01_minimal/minimal.cpp +++ b/examples/log/01_minimal/minimal.cpp @@ -5,17 +5,19 @@ namespace ML = myx::log; int main( int argc, char** argv ) { - ML::defaultLogger.enableStdoutSink(); + (void)argc; + (void)argv; + ML::default_logger.enableStdoutSink(); - spdlog::register_logger( ML::defaultLogger.logger() ); - spdlog::set_default_logger( ML::defaultLogger.logger() ); + spdlog::register_logger( ML::default_logger.logger() ); + spdlog::set_default_logger( ML::default_logger.logger() ); - ML::info( "aaaa" ); - ML::trace( "bbbb" ); + ML::info( "info" ); + ML::trace( "trace" ); spdlog::set_pattern( "[%H:%M:%S %z] %v" ); - ML::info( "aaaa 111" ); - ML::trace( "bbbb 111" ); + ML::info( "new info" ); + ML::trace( "new trace" ); return( 0 ); } diff --git a/examples/log/02_qt/CMakeLists.txt b/examples/log/02_qt/CMakeLists.txt index 0e85ab7..630089b 100644 --- a/examples/log/02_qt/CMakeLists.txt +++ b/examples/log/02_qt/CMakeLists.txt @@ -19,6 +19,9 @@ add_clazy_check(${current_target} ${current_target_sources}) add_uncrustify_format(${current_target} ${current_target_sources}) add_pvs_check(${current_target}) +add_dependencies(${current_target} base) +add_dependencies(${current_target} log) + # Qt5 # qt_translation(TARGET ${current_target} TS_DIR ${CMAKE_SOURCE_DIR}/l10n LANGUAGES ru_RU) target_include_directories(${current_target} PRIVATE ${CMAKE_SOURCE_DIR}/src) @@ -27,7 +30,7 @@ target_include_directories(${current_target} SYSTEM PUBLIC ${SPDLOG_INCLUDE_DIRS target_include_directories(${current_target} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) target_compile_options(${current_target} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}") -target_link_libraries(${current_target} myx-log_static) +target_link_libraries(${current_target} myx-log) target_link_libraries(${current_target} Qt5::Core) # Имя выходного файла для цели diff --git a/examples/log/02_qt/qt.cpp b/examples/log/02_qt/qt.cpp index f63ee09..6ff73db 100644 --- a/examples/log/02_qt/qt.cpp +++ b/examples/log/02_qt/qt.cpp @@ -6,19 +6,21 @@ namespace ML = myx::log; int main( int argc, char** argv ) { - ML::defaultLogger.enableStdoutSink(); + (void)argc; + (void)argv; + ML::default_logger.enableStdoutSink(); - spdlog::register_logger( ML::defaultLogger.logger() ); - spdlog::set_default_logger( ML::defaultLogger.logger() ); + spdlog::register_logger( ML::default_logger.logger() ); + spdlog::set_default_logger( ML::default_logger.logger() ); qInstallMessageHandler( ML::spdlog_qt_message_handler ); - qInfo() << "aaaa"; - qDebug() << "bbbb"; + qInfo() << "info"; + qDebug() << "debug"; spdlog::set_pattern( "[%H:%M:%S %z] %v" ); - qInfo( "aaaa 111" ); - qDebug( "bbbb 111" ); + qInfo( "new info" ); + qDebug( "new debug" ); return( 0 ); } diff --git a/src/filesystem/paths.cpp b/src/filesystem/paths.cpp index ed9431a..4b0d38f 100644 --- a/src/filesystem/paths.cpp +++ b/src/filesystem/paths.cpp @@ -125,18 +125,19 @@ void Paths::setConfigFile( const QString& configFile ) bool Paths::updatePaths() { char* path = nullptr; - int length, dirname_length; + int fullPathLength; + int dirNameLength; - length = wai_getExecutablePath( nullptr, 0, &dirname_length ); - if ( length > 0 ) + fullPathLength = wai_getExecutablePath( nullptr, 0, &dirNameLength ); + if ( fullPathLength > 0 ) { - path = static_cast< char* >( malloc( static_cast< size_t >( length ) + 1 ) ); - if ( !path ) + path = new( std::nothrow ) char[static_cast< size_t >( fullPathLength ) + 1 ]; + if ( path == nullptr ) { return( false ); } - wai_getExecutablePath( path, length, &dirname_length ); - path[length] = '\0'; + wai_getExecutablePath( path, fullPathLength, &dirNameLength ); + path[fullPathLength] = '\0'; } else { @@ -144,9 +145,9 @@ bool Paths::updatePaths() } m_executableFile = QFile( path ); - path[dirname_length] = '\0'; + path[dirNameLength] = '\0'; m_binaryDirectory = path; - free( path ); + delete [] path; if ( m_binaryDirectory.absolutePath().endsWith( "/bin" ) ) { diff --git a/src/filesystem/paths.hpp b/src/filesystem/paths.hpp index 71f9b65..ccd22c7 100644 --- a/src/filesystem/paths.hpp +++ b/src/filesystem/paths.hpp @@ -42,7 +42,7 @@ public: bool updatePaths(); bool makePaths(); - QString findConfigFile( const QString& defaultConfigFile = "" ); + QString findConfigFile( const QString& defaultConfigFile = QLatin1String("") ); }; // class Paths } // namespace filesystem diff --git a/src/log/spdlog.cpp b/src/log/spdlog.cpp index b502c9d..bd38dc7 100644 --- a/src/log/spdlog.cpp +++ b/src/log/spdlog.cpp @@ -1,11 +1,11 @@ -#include "config.hpp" #include "spdlog.hpp" +#include "config.hpp" namespace myx { namespace log { -Logger defaultLogger( "default" ); +Logger default_logger( "default" ); spdlog::level::level_enum Logger::outputLevel() const @@ -14,7 +14,7 @@ spdlog::level::level_enum Logger::outputLevel() const } -void Logger::setOutputLevel( const spdlog::level::level_enum& outputLevel ) +void Logger::setOutputLevel( const spdlog::level::level_enum outputLevel ) { m_outputLevel = outputLevel; } @@ -26,7 +26,7 @@ spdlog::level::level_enum Logger::flushLevel() const } -void Logger::setFlushLevel( const spdlog::level::level_enum& flushLevel ) +void Logger::setFlushLevel( const spdlog::level::level_enum flushLevel ) { m_flushLevel = flushLevel; } @@ -44,12 +44,12 @@ void Logger::setOutputPattern( const std::string& outputPattern ) } -Logger::Logger( const std::string& name ) : +Logger::Logger( std::string name ) : m_logger( nullptr ), - m_name( name ), + m_name( std::move( name ) ), m_outputPattern( "[%H:%M:%S %z] [%n] [%^---%L---%$] %v" ), m_baseFileName( fmt::format( "{}_{}", PROJECT_NAME, "st" ) ), - m_maxRotatingFileSize( 256 * 1024 ), + m_maxRotatingFileSize( rotatingFileSize ), m_maxRotatingFilesCount( 3 ), m_outputLevel( spdlog::level::trace ), m_flushLevel( spdlog::level::warn ), @@ -113,8 +113,8 @@ void Logger::disableNullSink() { if ( m_nullSink != nullptr ) { - m_logger->sinks().erase( std::remove( m_logger->sinks().begin(), m_logger->sinks().end(), m_nullSink ), - m_logger->sinks().end() ); + auto sinks = m_logger->sinks(); + sinks.erase( std::remove( sinks.begin(), sinks.end(), m_nullSink ), sinks.end() ); m_nullSink.reset(); m_nullSink = nullptr; } @@ -135,8 +135,8 @@ void Logger::disableStdoutSink() { if ( m_stdoutSink != nullptr ) { - m_logger->sinks().erase( std::remove( m_logger->sinks().begin(), m_logger->sinks().end(), m_stdoutSink ), - m_logger->sinks().end() ); + auto sinks = m_logger->sinks(); + sinks.erase( std::remove( sinks.begin(), sinks.end(), m_stdoutSink ), sinks.end() ); m_stdoutSink.reset(); m_stdoutSink = nullptr; } @@ -157,8 +157,8 @@ void Logger::disableStderrSink() { if ( m_stderrSink != nullptr ) { - m_logger->sinks().erase( std::remove( m_logger->sinks().begin(), m_logger->sinks().end(), m_stderrSink ), - m_logger->sinks().end() ); + auto sinks = m_logger->sinks(); + sinks.erase( std::remove( sinks.begin(), sinks.end(), m_stderrSink ), sinks.end() ); m_stderrSink.reset(); m_stderrSink = nullptr; } @@ -179,8 +179,8 @@ void Logger::disableSyslogSink() { if ( m_syslogSink != nullptr ) { - m_logger->sinks().erase( std::remove( m_logger->sinks().begin(), m_logger->sinks().end(), m_syslogSink ), - m_logger->sinks().end() ); + auto sinks = m_logger->sinks(); + sinks.erase( std::remove( sinks.begin(), sinks.end(), m_syslogSink ), sinks.end() ); m_syslogSink.reset(); m_syslogSink = nullptr; } @@ -201,8 +201,8 @@ void Logger::disableBasicFileSink() { if ( m_basicFileSink != nullptr ) { - m_logger->sinks().erase( std::remove( m_logger->sinks().begin(), m_logger->sinks().end(), m_basicFileSink ), - m_logger->sinks().end() ); + auto sinks = m_logger->sinks(); + sinks.erase( std::remove( sinks.begin(), sinks.end(), m_basicFileSink ), sinks.end() ); m_basicFileSink.reset(); m_basicFileSink = nullptr; } @@ -223,8 +223,8 @@ void Logger::disableRotatingFileSink() { if ( m_rotatingFileSink != nullptr ) { - m_logger->sinks().erase( std::remove( m_logger->sinks().begin(), m_logger->sinks().end(), m_rotatingFileSink ), - m_logger->sinks().end() ); + auto sinks = m_logger->sinks(); + sinks.erase( std::remove( sinks.begin(), sinks.end(), m_rotatingFileSink ), sinks.end() ); m_rotatingFileSink.reset(); m_rotatingFileSink = nullptr; } @@ -247,8 +247,8 @@ void Logger::disableDailyFileSink() { if ( m_dailyFileSink != nullptr ) { - m_logger->sinks().erase( std::remove( m_logger->sinks().begin(), m_logger->sinks().end(), m_dailyFileSink ), - m_logger->sinks().end() ); + auto sinks = m_logger->sinks(); + sinks.erase( std::remove( sinks.begin(), sinks.end(), m_dailyFileSink ), sinks.end() ); m_dailyFileSink.reset(); m_dailyFileSink = nullptr; } diff --git a/src/log/spdlog.hpp b/src/log/spdlog.hpp index 0210464..6016bb3 100644 --- a/src/log/spdlog.hpp +++ b/src/log/spdlog.hpp @@ -1,6 +1,7 @@ #ifndef MYX_LOG_SPDLOG_HPP_ #define MYX_LOG_SPDLOG_HPP_ +#include #include #include #include @@ -11,6 +12,8 @@ namespace myx { namespace log { +const size_t rotatingFileSize = 256 * 1024; + class Logger { std::shared_ptr< spdlog::logger > m_logger; @@ -30,7 +33,7 @@ class Logger std::shared_ptr< spdlog::sinks::daily_file_sink_st > m_dailyFileSink; public: - Logger( const std::string& name ); + Logger( std::string name ); void init(); std::shared_ptr< spdlog::logger > logger(); @@ -54,61 +57,61 @@ public: void enableDailyFileSink(); void disableDailyFileSink(); spdlog::level::level_enum outputLevel() const; - void setOutputLevel( const spdlog::level::level_enum& outputLevel ); + void setOutputLevel( const spdlog::level::level_enum outputLevel ); spdlog::level::level_enum flushLevel() const; - void setFlushLevel( const spdlog::level::level_enum& flushLevel ); + void setFlushLevel( const spdlog::level::level_enum flushLevel ); std::string outputPattern() const; void setOutputPattern( const std::string& outputPattern ); }; // class Logger -extern Logger defaultLogger; +extern Logger default_logger; template < class F, class ... Args > void trace( F&& format, Args&& ... args ) noexcept { - defaultLogger.logger()->trace( std::forward< F >( format ), - std::forward< Args >( args )... ); + default_logger.logger()->trace( std::forward< F >( format ), + std::forward< Args >( args )... ); } template < class F, class ... Args > void debug( F&& format, Args&& ... args ) noexcept { - defaultLogger.logger()->debug( std::forward< F >( format ), - std::forward< Args >( args )... ); + default_logger.logger()->debug( std::forward< F >( format ), + std::forward< Args >( args )... ); } template < class F, class ... Args > void info( F&& format, Args&& ... args ) noexcept { - defaultLogger.logger()->info( std::forward< F >( format ), - std::forward< Args >( args )... ); + default_logger.logger()->info( std::forward< F >( format ), + std::forward< Args >( args )... ); } template < class F, class ... Args > void warn( F&& format, Args&& ... args ) noexcept { - defaultLogger.logger()->warn( std::forward< F >( format ), - std::forward< Args >( args )... ); + default_logger.logger()->warn( std::forward< F >( format ), + std::forward< Args >( args )... ); } template < class F, class ... Args > void error( F&& format, Args&& ... args ) noexcept { - defaultLogger.logger()->error( std::forward< F >( format ), - std::forward< Args >( args )... ); + default_logger.logger()->error( std::forward< F >( format ), + std::forward< Args >( args )... ); } template < class F, class ... Args > void log( spdlog::level::level_enum lv, F&& format, Args&& ... args ) noexcept { - defaultLogger.logger()->log( lv, std::forward< F >( format ), - std::forward< Args >( args )... ); + default_logger.logger()->log( lv, std::forward< F >( format ), + std::forward< Args >( args )... ); } } // namespace log diff --git a/src/log/spdlog_qt.cpp b/src/log/spdlog_qt.cpp index 0246836..04795d2 100644 --- a/src/log/spdlog_qt.cpp +++ b/src/log/spdlog_qt.cpp @@ -9,30 +9,31 @@ namespace log { void spdlog_qt_message_handler( QtMsgType type, const QMessageLogContext& context, const QString& qMsg ) { - if ( !defaultLogger.logger() ) + Q_UNUSED( context ) + + if ( !default_logger.logger() ) { return; } - Q_UNUSED( context ) - const char* msg = qMsg.toUtf8().constData(); + auto message = qMsg.toUtf8(); switch ( type ) { case QtDebugMsg: - defaultLogger.logger()->debug( msg ); + default_logger.logger()->debug( message.constData() ); break; case QtInfoMsg: - defaultLogger.logger()->info( msg ); + default_logger.logger()->info( message.constData() ); break; case QtWarningMsg: - defaultLogger.logger()->warn( msg ); + default_logger.logger()->warn( message.constData() ); break; case QtCriticalMsg: - defaultLogger.logger()->critical( msg ); + default_logger.logger()->critical( message.constData() ); break; case QtFatalMsg: - defaultLogger.logger()->critical( "FATAL: %s", msg ); + default_logger.logger()->critical( "FATAL: %s", message.constData() ); QCoreApplication::exit( 1 ); break; } diff --git a/thirdparty/whereami/whereami.c b/thirdparty/whereami/whereami.c index 1ba83a6..5bc2e5f 100644 --- a/thirdparty/whereami/whereami.c +++ b/thirdparty/whereami/whereami.c @@ -263,7 +263,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) if (!fgets(buffer, sizeof(buffer), maps)) break; - if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) + if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %4s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) { uint64_t addr = (uintptr_t)WAI_RETURN_ADDRESS(); if (low <= addr && addr <= high)