spdlog/include/c11log/factory.h

96 lines
2.9 KiB
C
Raw Normal View History

2014-03-22 20:11:17 +08:00
#pragma once
#include <memory>
#include "logger.h"
#include "sinks/file_sinks.h"
#include "sinks/stdout_sinks.h"
2014-09-02 05:24:35 +08:00
//
// logger creation shotcuts
//
2014-03-22 20:11:17 +08:00
namespace c11log
{
namespace factory
2014-03-22 20:11:17 +08:00
{
2014-09-02 05:24:35 +08: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>();
return std::unique_ptr<logger>(new logger(name, sink));
}
2014-09-02 05:24:35 +08:00
std::unique_ptr<logger> stdout_logger_mt(const std::string& name = "")
{
auto sink = std::make_shared<sinks::stderr_sink_mt>();
return std::unique_ptr<logger>(new logger(name, sink));
}
2014-09-02 05:24:35 +08: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);
return std::unique_ptr<logger>(new c11log::logger(logger_name, fsink));
2014-03-22 20:11:17 +08: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);
return std::unique_ptr<logger>(new c11log::logger(logger_name, fsink));
2014-03-22 20:11:17 +08: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 20:11:17 +08:00
{
auto fsink = std::make_shared<sinks::daily_file_sink_st>(filename, extension, flush_every);
return std::unique_ptr<logger>(new c11log::logger(logger_name, fsink));
2014-03-22 20:11:17 +08: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 20:11:17 +08:00
{
auto fsink = std::make_shared<sinks::daily_file_sink_mt>(filename, extension, flush_every);
return std::unique_ptr<logger>(new c11log::logger(logger_name, fsink));
2014-03-22 20:11:17 +08: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);
return std::unique_ptr<logger>(new c11log::logger(logger_name, fsink));
}
2014-09-02 05:24:35 +08: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 20:11:17 +08:00
{
auto fsink = std::make_shared<sinks::rotating_file_sink_mt>(filename, extension, max_size, max_files, flush_every);
return std::unique_ptr<logger>(new c11log::logger(logger_name, fsink));
2014-03-22 20:11:17 +08:00
}
} // ns factory
} // ns c11log