44#define COLOUR_BLACK "\033[0;30m"
45#define COLOUR_DARK_GRAY "\033[1;30m"
46#define COLOUR_LIGHT_GRAY "\033[0;37m"
47#define COLOUR_RED "\033[0;31m"
48#define COLOUR_LIGHT_RED "\033[1;31m"
49#define COLOUR_GREEN "\033[0;32m"
50#define COLOUR_LIGHT_GREEN "\033[1;32m"
51#define COLOUR_BROWN_ORANGE "\033[0;33m"
52#define COLOUR_YELLOW "\033[1;33m"
53#define COLOUR_BLUE "\033[0;34m"
54#define COLOUR_LIGHT_BLUE "\033[1;34m"
55#define COLOUR_PURPLE "\033[0;35m"
56#define COLOUR_LIGHT_PURPLE "\033[1;35m"
57#define COLOUR_CYAN "\033[0;36m"
58#define COLOUR_LIGHT_CYAN "\033[1;36m"
59#define COLOUR_WHITE "\033[1;37m"
60#define COLOUR_RESET "\033[0m"
94 m_max_level(max_level),
95 m_to_stderr(to_stderr),
96 m_to_syslog(to_syslog)
105 openlog(PACKAGE, 0, LOG_USER);
111 std::lock_guard<std::recursive_mutex> lock_mutex(
m_mutex);
116 std::string time_string(
sizeof(
"YYYY-MM-DD MM:HH:SS.###"),
'\0');
118 std::string loglevel;
119 std::string filename;
122 gettimeofday(&tv, NULL);
124 millisec = std::lrint(
static_cast<double>(tv.tv_usec) / 1000.0);
125 if (millisec >= 1000)
134 time_string.resize(strftime(&time_string[0], time_string.size(), fmt.c_str(), localtime_r(&tv.tv_sec, &buf)));
147 filename =
"INPUT [" + filename +
"] ";
151 filename =
"OUTPUT [" + filename +
"] ";
155 std::string cachepath;
161 filename =
"CACHE [" + filename +
"] ";
165 if (filename.size() && filename[0] ==
'/')
167 filename.erase(0, 1);
169 filename =
"OTHER [" + filename +
"] ";
181 m_logging->m_logfile << time_string <<
" " << loglevel <<
" " << filename << msg << std::endl;
186 if (!filename.empty())
207 return {loglevel, filename};
218 m_logging = std::make_unique<Logging>(logfile, max_level, to_stderr, to_syslog);
228 log_with_level(loglevel, std::string(filename !=
nullptr ? filename :
""), message);
233 Log(loglevel, filename) << message;
237 const size_t __attribute__((unused)) index_to_replace)
239 return string_to_update;
const LOGLEVEL m_loglevel
Log level required to write log entry.
const std::string m_filename
Name of file for which this log entry was written. May be empty.
virtual ~Logger()
Destroy Logger object.
static const std::map< LOGLEVEL, int > m_syslog_level_map
Map our log levels to syslog levels.
static const std::map< LOGLEVEL, std::string > m_level_name_map
Map log level enums to strings.
static const std::map< LOGLEVEL, std::string > m_level_colour_map
Map log level enums to colours (logging to stderr only)
bool GetFail() const
Check whether either failbit or badbit is set.
static void log_with_level(LOGLEVEL loglevel, const char *filename, const std::string &message)
Write log entry.
static bool init_logging(const std::string &logfile, LOGLEVEL max_level, bool to_stderr, bool to_syslog)
Initialise the logging facility.
static std::unique_ptr< Logging > m_logging
Reference to self, Logging is a singleton.
static std::string format_helper(const std::string &string_to_update, const size_t __attribute__((unused)) index_to_replace)
Standard format_helper without parameters.
Logging(const std::string &logfile, LOGLEVEL max_level, bool to_stderr, bool to_syslog)
friend Logger Log(LOGLEVEL loglevel, const std::string &filename)
Make logger class our friend for our constructor.
std::ofstream m_logfile
Log file object for writing to disk.
static std::recursive_mutex m_mutex
Access mutex.
const bool m_to_syslog
Whether to write log output to syslog.
LOGLEVEL
Logging level types enum.
std::string & trim(std::string &s)
trim from both ends
bool replace_start(std::string *str, const std::string &from, const std::string &to)
Replace start of string from "from" to "to".
const std::string & strsprintf(std::string *str, const std::string &format, Args ... args)
Format a std::string sprintf-like.
FFMPEGFS_PARAMS params
FFmpegfs command line parameters.
Main include for FFmpegfs project.
void transcoder_cache_path(std::string *path)
Get transcoder cache path.
#define COLOUR_DARK_GRAY
ANSI ESC for dark gray foreground.
#define COLOUR_GREEN
ANSI ESC for green foreground.
#define COLOUR_RED
ANSI ESC for red foreground.
#define COLOUR_WHITE
ANSI ESC for white foreground.
#define COLOUR_RESET
ANSI ESC to reset the foreground colour.
#define COLOUR_YELLOW
ANSI ESC for yellow foreground.
#define COLOUR_LIGHT_PURPLE
ANSI ESC for light purple foreground.
#define COLOUR_BLUE
ANSI ESC for blue foreground.
#define COLOUR_LIGHT_RED
ANSI ESC for light red foreground.
Provide various log facilities to stderr, disk or syslog.
constexpr Logging::LOGLEVEL LOGDEBUG
Shorthand for log level DEBUG.
constexpr Logging::LOGLEVEL LOGTRACE
Shorthand for log level TRACE.
constexpr Logging::LOGLEVEL LOGWARN
Shorthand for log level WARNING.
constexpr Logging::LOGLEVEL LOGERROR
Shorthand for log level ERROR.
constexpr Logging::LOGLEVEL LOGINFO
Shorthand for log level INFO.
std::string m_mountpath
Mount path: Files from m_mountpath will be mapped to this directory.
std::string m_basepath
Base path: Files from this directory (including all sub directories) will be mapped to m_mountpath.