spdlog/include/c11log/factory.h

96 lines
2.9 KiB
C
Raw Normal View History

2014-03-22 08:11:17 -04:00
#pragma once
#include <memory>
#include "logger.h"
#include "sinks/file_sinks.h"
#include "sinks/stdout_sinks.h"
2014-09-01 17:24:35 -04:00
//
// logger creation shotcuts
//
2014-03-22 08:11:17 -04:00
namespace c11log
{
namespace factory
2014-03-22 08:11:17 -04:00
{
2014-09-01 17:24:35 -04:00
//
// console loggers single/multi threaded
//
std::unique_ptr<logger> stdout_logger(const std::string& name = "")
{
auto sink = std::make_shared<sinks::stderr_sink_st>();
2014-10-14 01:00:39 -04:00
return std::unique_ptr<logger>(new logger(name, { sink }));
}
2014-09-01 17:24:35 -04:00
std::unique_ptr<logger> stdout_logger_mt(const std::string& name = "")
{
auto sink = std::make_shared<sinks::stderr_sink_mt>();
2014-10-14 01:00:39 -04:00
return std::unique_ptr<logger>(new logger(name, { sink }));
}
2014-09-01 17:24:35 -04:00
//
// simple file logger single/multi threaded
//
std::unique_ptr<logger> simple_file_logger(const std::string& filename, const std::string& logger_name = "" )
{
auto fsink = std::make_shared<sinks::simple_file_sink_st>(filename);
2014-10-14 01:00:39 -04:00
return std::unique_ptr<logger>(new c11log::logger(logger_name, { fsink }));
2014-03-22 08:11:17 -04:00
}
std::unique_ptr<logger> simple_file_logger_mt(const std::string& filename, const std::string& logger_name = "")
{
auto fsink = std::make_shared<sinks::simple_file_sink_mt>(filename);
2014-10-14 01:00:39 -04:00
return std::unique_ptr<logger>(new c11log::logger(logger_name, { fsink }));
2014-03-22 08:11:17 -04:00
}
//
// daily file logger single/multi threaded
//
std::unique_ptr<logger> daily_file_logger(
const std::string &filename,
const std::string &extension,
const std::size_t flush_every,
const std::string& logger_name = "")
2014-03-22 08:11:17 -04:00
{
auto fsink = std::make_shared<sinks::daily_file_sink_st>(filename, extension, flush_every);
2014-10-14 01:00:39 -04:00
return std::unique_ptr<logger>(new c11log::logger(logger_name, { fsink }));
2014-03-22 08:11:17 -04:00
}
std::unique_ptr<logger> daily_file_logger_mt(
const std::string &filename,
const std::string &extension,
const std::size_t flush_every,
const std::string& logger_name = "")
2014-03-22 08:11:17 -04:00
{
auto fsink = std::make_shared<sinks::daily_file_sink_mt>(filename, extension, flush_every);
2014-10-14 01:00:39 -04:00
return std::unique_ptr<logger>(new c11log::logger(logger_name, { fsink }));
2014-03-22 08:11:17 -04:00
}
//
// rotating file logger single/multi threaded
//
std::unique_ptr<logger> rotating_file_logger(
const std::string &filename,
const std::string &extension,
const std::size_t max_size,
const std::size_t max_files,
const std::size_t flush_every,
const std::string& logger_name = "")
{
auto fsink = std::make_shared<sinks::rotating_file_sink_st>(filename, extension, max_size, max_files, flush_every);
2014-10-14 01:00:39 -04:00
return std::unique_ptr<logger>(new c11log::logger(logger_name, { fsink }));
}
2014-09-01 17:24:35 -04:00
std::unique_ptr<logger> rotating_file_logger_mt(
const std::string &filename,
const std::string &extension,
const std::size_t max_size,
const std::size_t max_files,
const std::size_t flush_every,
const std::string& logger_name = "")
2014-03-22 08:11:17 -04:00
{
auto fsink = std::make_shared<sinks::rotating_file_sink_mt>(filename, extension, max_size, max_files, flush_every);
2014-10-14 01:00:39 -04:00
return std::unique_ptr<logger>(new c11log::logger(logger_name, { fsink }));
2014-03-22 08:11:17 -04:00
}
} // ns factory
} // ns c11log