Обновление работы в whereami
This commit is contained in:
@@ -11,10 +11,13 @@ set(current_target_headers
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/paths.hpp
|
||||
)
|
||||
|
||||
add_common_library(TARGET ${current_target} OUTPUT_NAME myx-${current_target}
|
||||
SOURCES ${current_target_sources}
|
||||
${CMAKE_SOURCE_DIR}/thirdparty/whereami/whereami.c)
|
||||
add_common_library(TARGET ${current_target}
|
||||
OUTPUT_NAME myx-${current_target}
|
||||
SOURCES ${current_target_sources})
|
||||
common_target_properties(${current_target})
|
||||
add_dependencies(${current_target} whereami)
|
||||
|
||||
|
||||
add_clang_tidy_check(${current_target} ${current_target_sources})
|
||||
add_clang_analyze_check(${current_target} ${current_target_sources})
|
||||
add_clazy_check(${current_target} ${current_target_sources})
|
||||
@@ -25,7 +28,7 @@ target_include_directories(${current_target} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIR
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${FMT_INCLUDE_DIRS})
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${SPDLOG_INCLUDE_DIRS})
|
||||
target_include_directories(${current_target} PRIVATE ${CMAKE_SOURCE_DIR}/src/base)
|
||||
target_include_directories(${current_target} PRIVATE ${CMAKE_SOURCE_DIR}/thirdparty/whereami)
|
||||
target_include_directories(${current_target} PRIVATE ${CMAKE_BINARY_DIR}/include)
|
||||
|
||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
||||
add_custom_target(${current_target}-install-headers
|
||||
|
@@ -1,13 +1,62 @@
|
||||
#include "paths.hpp"
|
||||
#include "config.hpp"
|
||||
#include "whereami.h"
|
||||
#include "whereami++.h"
|
||||
|
||||
#include <paths.h>
|
||||
#include <QString>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
QString Paths::executableFileName() const
|
||||
{
|
||||
return( m_executableFileName );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setExecutableFileName( const QString& executableFileName )
|
||||
{
|
||||
m_executableFileName = executableFileName;
|
||||
}
|
||||
|
||||
|
||||
QString Paths::configFileName() const
|
||||
{
|
||||
return( m_configFileName );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setConfigFileName( const QString& configFileName )
|
||||
{
|
||||
m_configFileName = configFileName;
|
||||
}
|
||||
|
||||
|
||||
QFileInfo Paths::executableFilePath() const
|
||||
{
|
||||
return( m_executableFilePath );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setExecutableFilePath( const QFileInfo& executableFilePath )
|
||||
{
|
||||
m_executableFilePath = executableFilePath;
|
||||
}
|
||||
|
||||
|
||||
QFileInfo Paths::configFilePath() const
|
||||
{
|
||||
return( m_configFilePath );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setConfigFilePath( const QFileInfo& configFilePath )
|
||||
{
|
||||
m_configFilePath = configFilePath;
|
||||
}
|
||||
|
||||
|
||||
Paths::Paths() :
|
||||
m_prefixDirectory( "/opt/" ORGANIZATION_NAME_LOWER "/" PROJECT_NAME_LOWER ),
|
||||
m_binaryDirectory( m_prefixDirectory.absolutePath() + "/bin" ),
|
||||
@@ -16,8 +65,10 @@ Paths::Paths() :
|
||||
m_tempDirectory( QString::fromLocal8Bit( qgetenv( qPrintable( "TMPDIR" ) ) ) ),
|
||||
m_dataDirectory( m_prefixDirectory.absolutePath() + "/share" ),
|
||||
m_homeDirectory( QString::fromLocal8Bit( qgetenv( qPrintable( "HOME" ) ) ) ),
|
||||
m_executableFile( m_binaryDirectory.absolutePath() + "/" + PROJECT_NAME_LOWER ),
|
||||
m_configFile( m_configDirectory.absolutePath() + "/" + PROJECT_NAME_LOWER + ".conf" )
|
||||
m_executableFileName( PROJECT_NAME_LOWER ),
|
||||
m_configFileName( PROJECT_NAME_LOWER ".conf" ),
|
||||
m_executableFilePath( m_binaryDirectory.absolutePath() + "/" + m_executableFileName ),
|
||||
m_configFilePath( m_binaryDirectory.absolutePath() + "/" + m_configFileName )
|
||||
{
|
||||
if ( m_tempDirectory.isEmpty() || ( m_tempDirectory.path() == "." ) )
|
||||
{
|
||||
@@ -98,56 +149,13 @@ void Paths::setDataDirectory( const QString& dataDirectory )
|
||||
}
|
||||
|
||||
|
||||
QFileInfo Paths::executableFile() const
|
||||
{
|
||||
return( m_executableFile );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setExecutableFile( const QString& executableFile )
|
||||
{
|
||||
m_executableFile = executableFile;
|
||||
}
|
||||
|
||||
|
||||
QFileInfo Paths::configFile() const
|
||||
{
|
||||
return( m_configFile );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setConfigFile( const QString& configFile )
|
||||
{
|
||||
m_configFile = configFile;
|
||||
}
|
||||
|
||||
|
||||
bool Paths::updatePaths()
|
||||
{
|
||||
char* path = nullptr;
|
||||
int fullPathLength;
|
||||
int dirNameLength;
|
||||
whereami::whereami_path_t executablePath = whereami::getExecutablePath();
|
||||
|
||||
fullPathLength = wai_getExecutablePath( nullptr, 0, &dirNameLength );
|
||||
if ( fullPathLength > 0 )
|
||||
{
|
||||
path = new( std::nothrow ) char[static_cast< size_t >( fullPathLength ) + 1 ];
|
||||
if ( path == nullptr )
|
||||
{
|
||||
return( false );
|
||||
}
|
||||
wai_getExecutablePath( path, fullPathLength, &dirNameLength );
|
||||
path[fullPathLength] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
return( false );
|
||||
}
|
||||
|
||||
m_executableFile = QFile( path );
|
||||
path[dirNameLength] = '\0';
|
||||
m_binaryDirectory = path;
|
||||
delete [] path;
|
||||
m_executableFileName = QString::fromStdString( executablePath.basename() );
|
||||
m_binaryDirectory = QString::fromStdString( executablePath.dirname() );
|
||||
m_executableFilePath = QFile( m_binaryDirectory.absolutePath() + "/" + m_executableFileName );
|
||||
|
||||
if ( m_binaryDirectory.absolutePath().endsWith( "/bin" ) )
|
||||
{
|
||||
@@ -155,7 +163,7 @@ bool Paths::updatePaths()
|
||||
m_configDirectory = m_prefixDirectory.absolutePath() + "/etc";
|
||||
m_cacheDirectory = m_prefixDirectory.absolutePath() + "/var";
|
||||
m_dataDirectory = m_prefixDirectory.absolutePath() + "/share";
|
||||
m_configFile = m_configDirectory.absolutePath() + "/" + PROJECT_NAME_LOWER + ".conf";
|
||||
m_configFilePath = QFile( m_configDirectory.absolutePath() + "/" + PROJECT_NAME_LOWER + ".conf" );
|
||||
}
|
||||
|
||||
if ( m_prefixDirectory.absolutePath().startsWith( "/opt" ) ||
|
||||
@@ -202,22 +210,24 @@ QString Paths::findConfigFile( const QString& defaultConfigFile )
|
||||
{
|
||||
if ( QFileInfo( defaultConfigFile ).isReadable() )
|
||||
{
|
||||
m_configFilePath = defaultConfigFile;
|
||||
return( defaultConfigFile );
|
||||
}
|
||||
|
||||
auto fileName = QString::fromLocal8Bit( qgetenv( qPrintable( PROJECT_NAME_UPPER "_CONFIG" ) ) );
|
||||
if ( QFileInfo( fileName ).isReadable() )
|
||||
{
|
||||
m_configFilePath = fileName;
|
||||
return( fileName );
|
||||
}
|
||||
|
||||
if ( QFileInfo( m_configFile ).isReadable() )
|
||||
if ( QFileInfo( m_configFilePath ).isReadable() )
|
||||
{
|
||||
return( m_configFile.absoluteFilePath() );
|
||||
return( m_configFilePath.absoluteFilePath() );
|
||||
}
|
||||
|
||||
return( QString() );
|
||||
}
|
||||
} // Paths::findConfigFile
|
||||
|
||||
} // namespace filesystem
|
||||
|
||||
|
@@ -18,8 +18,10 @@ class Paths
|
||||
QDir m_tempDirectory;
|
||||
QDir m_dataDirectory;
|
||||
QDir m_homeDirectory;
|
||||
QFileInfo m_executableFile;
|
||||
QFileInfo m_configFile;
|
||||
QString m_executableFileName;
|
||||
QString m_configFileName;
|
||||
QFileInfo m_executableFilePath;
|
||||
QFileInfo m_configFilePath;
|
||||
|
||||
public:
|
||||
Paths();
|
||||
@@ -35,14 +37,18 @@ public:
|
||||
void setTempDirectory( const QString& tempDirectory );
|
||||
QDir dataDirectory() const;
|
||||
void setDataDirectory( const QString& dataDirectory );
|
||||
QFileInfo executableFile() const;
|
||||
void setExecutableFile( const QString& executableFile );
|
||||
QFileInfo configFile() const;
|
||||
void setConfigFile( const QString& configFile );
|
||||
QString executableFileName() const;
|
||||
void setExecutableFileName( const QString& executableFileName );
|
||||
QString configFileName() const;
|
||||
void setConfigFileName( const QString& configFileName );
|
||||
QFileInfo executableFilePath() const;
|
||||
void setExecutableFilePath( const QFileInfo& executableFilePath );
|
||||
QFileInfo configFilePath() const;
|
||||
void setConfigFilePath( const QFileInfo& configFilePath );
|
||||
|
||||
bool updatePaths();
|
||||
bool makePaths();
|
||||
QString findConfigFile( const QString& defaultConfigFile = QLatin1String("") );
|
||||
QString findConfigFile( const QString& defaultConfigFile = "" );
|
||||
}; // class Paths
|
||||
|
||||
} // namespace filesystem
|
||||
|
@@ -8,6 +8,31 @@ namespace log {
|
||||
Logger default_logger( "default" );
|
||||
|
||||
|
||||
Logger::Logger( std::string name ) :
|
||||
m_logger( nullptr ),
|
||||
m_name( std::move( name ) ),
|
||||
m_outputPattern( "[%H:%M:%S %z] [%n] [%^---%L---%$] %v" ),
|
||||
m_baseFileName( fmt::format( "{}_{}", PROJECT_NAME, "st" ) ),
|
||||
m_maxRotatingFileSize( rotatingFileSize ),
|
||||
m_maxRotatingFilesCount( 3 ),
|
||||
m_outputLevel( spdlog::level::trace ),
|
||||
m_flushLevel( spdlog::level::warn ),
|
||||
m_nullSink( nullptr ),
|
||||
m_stdoutSink( nullptr ),
|
||||
m_stderrSink( nullptr ),
|
||||
m_syslogSink( nullptr ),
|
||||
m_basicFileSink( nullptr ),
|
||||
m_rotatingFileSink( nullptr ),
|
||||
m_dailyFileSink( nullptr )
|
||||
{
|
||||
m_logger = std::make_shared< spdlog::logger >( m_name, nullptr );
|
||||
m_logger->sinks().clear();
|
||||
m_logger->flush_on( m_flushLevel );
|
||||
m_logger->set_level( m_outputLevel );
|
||||
m_logger->set_pattern( m_outputPattern );
|
||||
}
|
||||
|
||||
|
||||
spdlog::level::level_enum Logger::outputLevel() const
|
||||
{
|
||||
return( m_outputLevel );
|
||||
@@ -44,31 +69,6 @@ void Logger::setOutputPattern( const std::string& outputPattern )
|
||||
}
|
||||
|
||||
|
||||
Logger::Logger( std::string name ) :
|
||||
m_logger( nullptr ),
|
||||
m_name( std::move( name ) ),
|
||||
m_outputPattern( "[%H:%M:%S %z] [%n] [%^---%L---%$] %v" ),
|
||||
m_baseFileName( fmt::format( "{}_{}", PROJECT_NAME, "st" ) ),
|
||||
m_maxRotatingFileSize( rotatingFileSize ),
|
||||
m_maxRotatingFilesCount( 3 ),
|
||||
m_outputLevel( spdlog::level::trace ),
|
||||
m_flushLevel( spdlog::level::warn ),
|
||||
m_nullSink( nullptr ),
|
||||
m_stdoutSink( nullptr ),
|
||||
m_stderrSink( nullptr ),
|
||||
m_syslogSink( nullptr ),
|
||||
m_basicFileSink( nullptr ),
|
||||
m_rotatingFileSink( nullptr ),
|
||||
m_dailyFileSink( nullptr )
|
||||
{
|
||||
m_logger = std::make_shared< spdlog::logger >( m_name, nullptr );
|
||||
m_logger->sinks().clear();
|
||||
m_logger->flush_on( m_flushLevel );
|
||||
m_logger->set_level( m_outputLevel );
|
||||
m_logger->set_pattern( m_outputPattern );
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr< spdlog::logger > Logger::logger()
|
||||
{
|
||||
return( m_logger );
|
||||
|
Reference in New Issue
Block a user