FFmpegfs Fuse Multi Media Filesystem 2.14
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Static Private Member Functions | Friends | List of all members
Logging Class Reference

Logging facility More...

#include <logging.h>

Collaboration diagram for Logging:
Collaboration graph
[legend]

Classes

class  Logger
 Logging helper class. More...
 

Public Types

enum class  LOGLEVEL {
  LOGERROR = 1 , LOGWARN = 2 , LOGINFO = 3 , LOGDEBUG = 4 ,
  LOGTRACE = 5
}
 Logging level types enum. More...
 

Public Member Functions

 Logging (const std::string &logfile, LOGLEVEL max_level, bool to_stderr, bool to_syslog)
 
bool GetFail () const
 Check whether either failbit or badbit is set. More...
 

Static Public Member Functions

static bool init_logging (const std::string &logfile, LOGLEVEL max_level, bool to_stderr, bool to_syslog)
 Initialise the logging facility. More...
 
template<typename T , typename... Args>
static void trace (const T filename, const std::string &format_string, Args &&...args)
 Write trace level log entry. More...
 
template<typename T , typename... Args>
static void debug (const T filename, const std::string &format_string, Args &&...args)
 Write debug level log entry. More...
 
template<typename T , typename... Args>
static void info (const T filename, const std::string &format_string, Args &&...args)
 Write info level log entry. More...
 
template<typename T , typename... Args>
static void warning (const T filename, const std::string &format_string, Args &&...args)
 Write warning level log entry. More...
 
template<typename T , typename... Args>
static void error (const T filename, const std::string &format_string, Args &&...args)
 Write error level log entry. More...
 
static void log_with_level (LOGLEVEL loglevel, const char *filename, const std::string &message)
 Write log entry. More...
 
static void log_with_level (LOGLEVEL loglevel, const std::string &filename, const std::string &message)
 Write log entry. More...
 
static bool show (LOGLEVEL loglevel)
 Check if log entry should be displayed at the current log level. More...
 

Protected Attributes

friend Logger
 Make logger class our friend. More...
 
std::ofstream m_logfile
 Log file object for writing to disk. More...
 
const LOGLEVEL m_max_level
 The maximum level of log output to write. More...
 
const bool m_to_stderr
 Whether to write log output to stderr. More...
 
const bool m_to_syslog
 Whether to write log output to syslog. More...
 

Static Protected Attributes

static Loggingm_logging
 Reference to self, Logging is a singleton. More...
 
static std::recursive_mutex m_mutex
 Access mutex. More...
 

Static Private Member Functions

static std::string format_helper (const std::string &string_to_update, const size_t __attribute__((unused)) index_to_replace)
 Standard format_helper without parameters. More...
 
template<typename T , typename... Args>
static std::string format_helper (const std::string &string_to_search, const size_t index_to_replace, T &&val, Args &&...args)
 format_helper with variadic parameters. More...
 
template<typename... Args>
static std::string format (const std::string &format_string, Args &&...args)
 format string with single token More...
 

Friends

Logger Log (LOGLEVEL loglevel, const std::string &filename)
 Make logger class our friend for our constructor. More...
 

Detailed Description

Logging facility

Within the log message text, escape sequences are supported for dynamically formatting the message.

Escape sequences have either the form n or %<format specifier>n, where the index n starts at 1.

The index specifies the position of the argument in the list. They can appear in any given order. An index can be used more than once, and not all indexes have to be present (in which case the argument will not be printed). The input value is automatically converted to string format and can be among std::string, char *, int, uint64_t and more.

The format specifier is the same as used in printf and sprintf.

int channels = 2;
int sample_rate = 44100:
Logging::debug(filename, "Audio %1 channels %2 KHz", channels, sample_rate);
static void debug(const T filename, const std::string &format_string, Args &&...args)
Write debug level log entry.
Definition: logging.h:182

Prints "Audio 2 channels 44100 KHz".

int channels = 2;
double sample_rate = 44.1:
Logging::debug(filename, "Audio %1 %<%.3f>2 KHz", channels == 2 ? "stereo" : "mono", sample_rate);

Prints "Audio stereo 44.100 KHz".

Definition at line 79 of file logging.h.

Member Enumeration Documentation

◆ LOGLEVEL

enum class Logging::LOGLEVEL
strong

Logging level types enum.

Enumerator
LOGERROR 

Error level.

LOGWARN 

Warning level.

LOGINFO 

Info level.

LOGDEBUG 

Debug level.

LOGTRACE 

Error level.

Definition at line 84 of file logging.h.

Constructor & Destructor Documentation

◆ Logging()

Logging::Logging ( const std::string &  logfile,
LOGLEVEL  max_level,
bool  to_stderr,
bool  to_syslog 
)
explicit

Construct Logging object.

Parameters
[in]logfile- The name of a file to write logging output to. If empty, no output will be written.
[in]max_level- The maximum level of log output to write.
[in]to_stderr- Whether to write log output to stderr.
[in]to_syslog- Whether to write log output to syslog.

Definition at line 93 of file logging.cc.

References m_logfile, and m_to_syslog.

Referenced by init_logging().

Member Function Documentation

◆ debug()

template<typename T , typename... Args>
static void Logging::debug ( const T  filename,
const std::string &  format_string,
Args &&...  args 
)
inlinestatic

Write debug level log entry.

Parameters
[in]filename- Name of the file for which this log entry was written. May be empty.
[in]format_string- Format a string in FFmpegfs logger format.
[in]args- 0 or more format arguments. See format.

Definition at line 182 of file logging.h.

References format_helper(), log_with_level(), LOGDEBUG, and show().

Referenced by FFmpeg_Transcoder::add_albumart_stream(), FFmpeg_Transcoder::add_external_subtitle_stream(), FFmpeg_Transcoder::add_stream(), FFmpeg_Transcoder::add_subtitle_stream(), FFmpeg_Base::audio_info(), FFmpeg_Transcoder::can_copy_stream(), create_dvd_virtualfile(), FFmpeg_Transcoder::decode_frame(), FFmpeg_Transcoder::decode_video_frame(), ffmpegfs_getattr(), ffmpegfs_readdir(), FFmpeg_Transcoder::get_hw_pix_fmt(), get_source_properties(), FFmpeg_Transcoder::init_deinterlace_filters(), FFmpeg_Transcoder::init_resampler(), FFmpeg_Transcoder::init_rescaler(), kick_next(), link_up(), Cache::load_index(), FFmpeg_Transcoder::open_bestmatch_video(), Buffer::open_file(), FFmpeg_Transcoder::open_input_file(), FFmpeg_Transcoder::open_output_file(), FFmpeg_Transcoder::open_output_filestreams(), FFmpeg_Transcoder::open_output_frame_set(), BlurayIO::openio(), DiskIO::openio(), DvdIO::openio(), Cache_Entry::outdated(), parse_bluray(), parse_dvd(), parse_file(), parse_vcd(), prepare_script(), FFmpeg_Base::subtitle_info(), thread_pool::tear_down(), transcode(), transcode_finish(), transcoder_free(), transcoder_init(), transcoder_new(), Cache::upgrade_db(), and FFmpeg_Base::video_info().

◆ error()

template<typename T , typename... Args>
static void Logging::error ( const T  filename,
const std::string &  format_string,
Args &&...  args 
)
inlinestatic

Write error level log entry.

Parameters
[in]filename- Name of the file for which this log entry was written. May be empty.
[in]format_string- Format a string in FFmpegfs logger format.
[in]args- 0 or more format arguments. See format.

Definition at line 239 of file logging.h.

References format_helper(), log_with_level(), LOGERROR, and show().

Referenced by FFmpeg_Transcoder::add_albumart_frame(), FFmpeg_Transcoder::add_albumart_stream(), FFmpeg_Transcoder::add_external_subtitle_stream(), FFmpeg_Transcoder::add_external_subtitle_streams(), FFmpeg_Transcoder::add_samples_to_fifo(), FFmpeg_Transcoder::add_stream(), FFmpeg_Transcoder::add_stream_copy(), FFmpeg_Transcoder::add_subtitle_stream(), FFmpeg_Transcoder::alloc_picture(), audio_stream_info(), Cache::begin_transaction(), check_cuesheet(), Cache::check_min_version(), Buffer::clear(), Cache::column_exists(), FFmpeg_Transcoder::convert_samples(), Buffer::copy(), FFmpeg_Transcoder::create_audio_frame(), create_bluray_virtualfile(), create_cuesheet_virtualfile(), create_dvd_virtualfile(), Cache::create_table_cache_entry(), create_vcd_virtualfile(), FFmpeg_Transcoder::decode(), FFmpeg_Transcoder::decode_audio_frame(), FFmpeg_Transcoder::decode_frame(), FFmpeg_Transcoder::decode_subtitle(), FFmpeg_Transcoder::decode_video_frame(), FFmpeg_Base::dict_set_with_check(), FFmpeg_Transcoder::encode_audio_frame(), FFmpeg_Transcoder::encode_image_frame(), FFmpeg_Transcoder::encode_subtitle(), FFmpeg_Transcoder::encode_video_frame(), Cache::end_transaction(), ffmpegfs_fgetattr(), ffmpegfs_read(), ffmpegfs_readdir(), ffmpegfs_release(), find_original(), Buffer::flush(), FFmpeg_Transcoder::flush_delayed_audio(), FFmpeg_Transcoder::flush_delayed_video(), FFmpeg_Transcoder::foreach_subtitle_file(), FFmpeg_Transcoder::get_format(), FFmpeg_Transcoder::get_hw_pix_fmt(), FFmpeg_Transcoder::hwdevice_ctx_add_ref(), FFmpeg_Transcoder::hwdevice_ctx_create(), FFmpeg_Transcoder::hwframe_copy_from_hw(), FFmpeg_Transcoder::hwframe_copy_to_hw(), FFmpeg_Transcoder::hwframe_ctx_set(), Buffer::init(), FFmpeg_Transcoder::init_audio_fifo(), FFmpeg_Transcoder::init_audio_output_frame(), FFmpeg_Transcoder::init_converted_samples(), FFmpeg_Transcoder::init_deinterlace_filters(), FFmpeg_Transcoder::init_resampler(), FFmpeg_Transcoder::init_rescaler(), FFmpeg_Transcoder::input_read(), link_down(), link_up(), Cache::load_index(), Buffer::map_file(), FFmpeg_Transcoder::open_albumarts(), FFmpeg_Transcoder::open_bestmatch_audio(), FFmpeg_Transcoder::open_bestmatch_decoder(), FFmpeg_Transcoder::open_bestmatch_video(), FFmpeg_Transcoder::open_decoder(), FFmpeg_Transcoder::open_input_file(), FFmpeg_Transcoder::open_output_file(), FFmpeg_Transcoder::open_output_filestreams(), FFmpeg_Transcoder::open_output_frame_set(), FFmpeg_Transcoder::open_subtitles(), BlurayIO::openio(), DvdIO::openio(), FFmpeg_Base::opt_set_with_check(), FFmpeg_Transcoder::output_write(), parse_cuesheet(), parse_dvd(), parse_file(), Cache::prepare_stmts(), FFmpeg_Transcoder::process_single_fr(), FFmpeg_Transcoder::read_decode_convert_and_store(), Cache::read_info(), BlurayIO::readio(), DvdIO::readio(), Buffer::reserve(), Cache::rollback_transaction(), FFmpeg_Transcoder::seek(), FFmpeg_Transcoder::send_filters(), FFmpeg_Transcoder::skip_decoded_frames(), FFmpeg_Transcoder::stack_seek_frame(), FFmpeg_Transcoder::stack_seek_segment(), FFmpeg_Transcoder::start_new_segment(), start_timer(), stop_timer(), FFmpeg_Transcoder::store_packet(), Cache::table_exists(), transcoder_init(), transcoder_read_frame(), transcoder_set_filesize(), transcoder_thread(), Buffer::unmap_file(), Cache::upgrade_db(), video_stream_info(), FFmpeg_Transcoder::write_output_file_header(), and FFmpeg_Transcoder::write_output_file_trailer().

◆ format()

template<typename... Args>
static std::string Logging::format ( const std::string &  format_string,
Args &&...  args 
)
inlinestaticprivate

format string with single token

Parameters
[in]format_string- Format string to be searched.
[in]args- arguments
Returns
Contents of format_string with all tokens replaced.

Definition at line 354 of file logging.h.

References format_helper().

◆ format_helper() [1/2]

template<typename T , typename... Args>
static std::string Logging::format_helper ( const std::string &  string_to_search,
const size_t  index_to_replace,
T &&  val,
Args &&...  args 
)
inlinestaticprivate

format_helper with variadic parameters.

Calls itself recursively until all tokens are replaced.

Parameters
[in]string_to_search- format string to be searched.
[in]index_to_replace- index number (n) to be replaced. May be present 0...x times.
[in]val- Replacement value to fill in tokens.
[in]args- Further arguments.
Returns
Contents of string_to_search with all tokens replaced.

Definition at line 300 of file logging.h.

References format_helper().

◆ format_helper() [2/2]

std::string Logging::format_helper ( const std::string &  string_to_update,
const size_t __attribute__((unused))  index_to_replace 
)
staticprivate

Standard format_helper without parameters.

Parameters
[in]string_to_update- Original string.
[in]index_to_replace- unused
Returns
Returns original string.

Definition at line 236 of file logging.cc.

Referenced by debug(), error(), format(), format_helper(), info(), trace(), and warning().

◆ GetFail()

bool Logging::GetFail ( ) const

Check whether either failbit or badbit is set.

Returns
Returns true if either (or both) the failbit or the badbit error state flags are set for the stream.

Definition at line 200 of file logging.cc.

References m_logfile.

Referenced by init_logging().

◆ info()

template<typename T , typename... Args>
static void Logging::info ( const T  filename,
const std::string &  format_string,
Args &&...  args 
)
inlinestatic

Write info level log entry.

Parameters
[in]filename- Name of the file for which this log entry was written. May be empty.
[in]format_string- Format a string in FFmpegfs logger format.
[in]args- 0 or more format arguments. See format.

Definition at line 201 of file logging.h.

References format_helper(), log_with_level(), LOGINFO, and show().

Referenced by FFmpeg_Transcoder::can_copy_stream(), ffmpegfs_destroy(), ffmpegfs_init(), thread_pool::init(), link_down(), link_up(), maintenance_handler(), master_check(), FFmpeg_Transcoder::open_bestmatch_video(), FFmpeg_Transcoder::open_output(), FFmpeg_Transcoder::open_output_filestreams(), VcdIO::openio(), FFmpeg_Transcoder::start_new_segment(), stop_timer(), transcode(), transcode_until(), transcoder_thread(), and Cache::upgrade_db().

◆ init_logging()

bool Logging::init_logging ( const std::string &  logfile,
LOGLEVEL  max_level,
bool  to_stderr,
bool  to_syslog 
)
static

Initialise the logging facility.

Parameters
[in]logfile- The name of a file to write logging output to. If empty, no output will be written.
[in]max_level- The maximum level of log output to write.
[in]to_stderr- Whether to write log output to stderr.
[in]to_syslog- Whether to write log output to syslog.
Returns
On success, returns true. On error, returns false.
Note
It will only fail if the file cannot be opened. Writing to stderr or syslog will never fail. errno is not set.

Definition at line 210 of file logging.cc.

References GetFail(), Logging(), and m_logging.

Referenced by init_logging().

◆ log_with_level() [1/2]

void Logging::log_with_level ( LOGLEVEL  loglevel,
const char *  filename,
const std::string &  message 
)
static

Write log entry.

Parameters
[in]loglevel- The level of log this message is for.
[in]filename- Name of the file for which this log entry was written. May be nullptr.
[in]message- Message to log.

Definition at line 226 of file logging.cc.

References log_with_level().

Referenced by debug(), error(), ffmpeg_log(), info(), log_with_level(), trace(), and warning().

◆ log_with_level() [2/2]

void Logging::log_with_level ( LOGLEVEL  loglevel,
const std::string &  filename,
const std::string &  message 
)
static

Write log entry.

Parameters
[in]loglevel- The level of log this message is for.
[in]filename- Name of the file for which this log entry was written. May be empty.
[in]message- Message to log.

Definition at line 231 of file logging.cc.

References Log.

◆ show()

static bool Logging::show ( LOGLEVEL  loglevel)
inlinestatic

Check if log entry should be displayed at the current log level.

Parameters
[in]loglevel- Log level of log entry.
Returns
True, if entry should be be shown; false if not.

Definition at line 272 of file logging.h.

References m_logging, and m_max_level.

Referenced by debug(), error(), ffmpeg_log(), info(), trace(), and warning().

◆ trace()

template<typename T , typename... Args>
static void Logging::trace ( const T  filename,
const std::string &  format_string,
Args &&...  args 
)
inlinestatic

Write trace level log entry.

Parameters
[in]filename- Name of the file for which this log entry was written. May be empty.
[in]format_string- Format a string in FFmpegfs logger format.
[in]args- 0 or more format arguments. See format.

Definition at line 163 of file logging.h.

References format_helper(), log_with_level(), LOGTRACE, and show().

Referenced by FFmpeg_Transcoder::add_albumart_frame(), FFmpeg_Transcoder::add_stream(), Cache_Entry::Cache_Entry(), check_bluray(), check_cuesheet(), check_dvd(), check_vcd(), Buffer::close_file(), FFmpeg_Transcoder::closeio(), Cache::closeio(), create_bluray_virtualfile(), create_dvd_virtualfile(), FFmpeg_Transcoder::encode_video_frame(), FFmpeg_Transcoder::FFmpeg_Transcoder(), ffmpegfs_fgetattr(), ffmpegfs_getattr(), ffmpegfs_open(), ffmpegfs_read(), ffmpegfs_readdir(), ffmpegfs_readlink(), ffmpegfs_release(), ffmpegfs_statfs(), get_format(), FFmpeg_Transcoder::init_rescaler(), thread_pool::loop_function(), Buffer::map_file(), master_check(), FFmpeg_Transcoder::open_albumarts(), FFmpeg_Transcoder::open_bestmatch_video(), Buffer::open_file(), Cache_Entry::openio(), Cache::openio(), DvdIO::openio(), parse_bluray(), parse_cuesheet_file(), parse_cuesheet_text(), parse_dvd(), parse_file(), prepare_script(), print_params(), FFmpeg_Transcoder::process_metadata(), FFmpeg_Transcoder::read_decode_convert_and_store(), Buffer::reallocate(), thread_pool::schedule_thread(), start_timer(), FFmpeg_Transcoder::store_packet(), transcode_until(), transcoder_new(), transcoder_predict_filesize(), transcoder_read(), transcoder_read_frame(), transcoder_set_filesize(), Buffer::unmap_file(), FFmpeg_Transcoder::update_codec(), FFmpeg_Transcoder::update_format(), Cache_Entry::~Cache_Entry(), and FFmpeg_Transcoder::~FFmpeg_Transcoder().

◆ warning()

template<typename T , typename... Args>
static void Logging::warning ( const T  filename,
const std::string &  format_string,
Args &&...  args 
)
inlinestatic

Write warning level log entry.

Parameters
[in]filename- Name of the file for which this log entry was written. May be empty.
[in]format_string- Format a string in FFmpegfs logger format.
[in]args- 0 or more format arguments. See format.

Definition at line 220 of file logging.h.

References format_helper(), log_with_level(), LOGWARN, and show().

Referenced by FFmpeg_Transcoder::calculate_predicted_filesize(), FFmpeg_Transcoder::encode_video_frame(), Cache::load_index(), FFmpeg_Transcoder::open_input_file(), BlurayIO::openio(), parse_dvd(), prepare_script(), FFmpeg_Transcoder::purge(), DvdIO::readio(), Buffer::remove_file(), FFmpeg_Transcoder::send_filters(), sighandler(), transcode_until(), transcoder_read_frame(), transcoder_set_filesize(), transcoder_thread(), and FFmpeg_Base::video_stream_setup().

Friends And Related Function Documentation

◆ Log

Logger Log ( Logging::LOGLEVEL  loglevel,
const std::string &  filename 
)
friend

Make logger class our friend for our constructor.

Parameters
[in]loglevel- The level of log this message is for.
[in]filename- Name of the file for which this log entry was written. May be empty.

Definition at line 205 of file logging.cc.

Referenced by log_with_level().

Member Data Documentation

◆ Logger

friend Logging::Logger
protected

Make logger class our friend.

Definition at line 366 of file logging.h.

◆ m_logfile

std::ofstream Logging::m_logfile
protected

Log file object for writing to disk.

Definition at line 370 of file logging.h.

Referenced by GetFail(), Logging(), and Logging::Logger::~Logger().

◆ m_logging

Logging * Logging::m_logging
staticprotected

Reference to self, Logging is a singleton.

Definition at line 368 of file logging.h.

Referenced by init_logging(), show(), and Logging::Logger::~Logger().

◆ m_max_level

const LOGLEVEL Logging::m_max_level
protected

The maximum level of log output to write.

Definition at line 371 of file logging.h.

Referenced by show().

◆ m_mutex

std::recursive_mutex Logging::m_mutex
staticprotected

Access mutex.

Definition at line 369 of file logging.h.

Referenced by Logging::Logger::~Logger().

◆ m_to_stderr

const bool Logging::m_to_stderr
protected

Whether to write log output to stderr.

Definition at line 372 of file logging.h.

Referenced by Logging::Logger::~Logger().

◆ m_to_syslog

const bool Logging::m_to_syslog
protected

Whether to write log output to syslog.

Definition at line 373 of file logging.h.

Referenced by Logging(), and Logging::Logger::~Logger().


The documentation for this class was generated from the following files: