@ -3,6 +3,7 @@
# pragma once
# pragma once
# include <unistd.h>
# include <spdlog/sinks/base_sink.h>
# include <spdlog/sinks/base_sink.h>
# include <spdlog/details/file_helper.h>
# include <spdlog/details/file_helper.h>
# include <spdlog/details/null_mutex.h>
# include <spdlog/details/null_mutex.h>
@ -22,7 +23,7 @@ template<typename Mutex>
class rotating_file_sink final : public base_sink < Mutex >
class rotating_file_sink final : public base_sink < Mutex >
{
{
public :
public :
rotating_file_sink ( filename_t base_filename , std : : size_t max_size , std : : size_t max_files , bool rotate_on_open = false );
rotating_file_sink ( filename_t base_filename , std : : size_t max_size , std : : size_t max_files , bool rotate_on_open = false , uid_t uid = - 1 , gid_t gid = - 1 );
static filename_t calc_filename ( const filename_t & filename , std : : size_t index ) ;
static filename_t calc_filename ( const filename_t & filename , std : : size_t index ) ;
filename_t filename ( ) ;
filename_t filename ( ) ;
@ -42,11 +43,15 @@ private:
// return true on success, false otherwise.
// return true on success, false otherwise.
bool rename_file_ ( const filename_t & src_filename , const filename_t & target_filename ) ;
bool rename_file_ ( const filename_t & src_filename , const filename_t & target_filename ) ;
void set_file_ownership ( filename_t filename ) ;
filename_t base_filename_ ;
filename_t base_filename_ ;
std : : size_t max_size_ ;
std : : size_t max_size_ ;
std : : size_t max_files_ ;
std : : size_t max_files_ ;
std : : size_t current_size_ ;
std : : size_t current_size_ ;
details : : file_helper file_helper_ ;
details : : file_helper file_helper_ ;
uid_t uid_ ;
gid_t gid_ ;
} ;
} ;
using rotating_file_sink_mt = rotating_file_sink < std : : mutex > ;
using rotating_file_sink_mt = rotating_file_sink < std : : mutex > ;
@ -60,9 +65,9 @@ using rotating_file_sink_st = rotating_file_sink<details::null_mutex>;
template < typename Factory = spdlog : : synchronous_factory >
template < typename Factory = spdlog : : synchronous_factory >
inline std : : shared_ptr < logger > rotating_logger_mt (
inline std : : shared_ptr < logger > rotating_logger_mt (
const std : : string & logger_name , const filename_t & filename , size_t max_file_size , size_t max_files , bool rotate_on_open = false )
const std : : string & logger_name , const filename_t & filename , size_t max_file_size , size_t max_files , bool rotate_on_open = false , uid_t uid = - 1 , gid_t gid = - 1 )
{
{
return Factory : : template create < sinks : : rotating_file_sink_mt > ( logger_name , filename , max_file_size , max_files , rotate_on_open );
return Factory : : template create < sinks : : rotating_file_sink_mt > ( logger_name , filename , max_file_size , max_files , rotate_on_open , uid , gid );
}
}
template < typename Factory = spdlog : : synchronous_factory >
template < typename Factory = spdlog : : synchronous_factory >