Leosac  0.8.0
Open Source Access Control
DatabaseLogSink.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "tools/db/db_fwd.hpp"
23 #include <spdlog/sinks/sink.h>
24 
25 namespace Leosac
26 {
27 namespace Tools
28 {
33 class DatabaseLogSink : public spdlog::sinks::sink
34 {
35  public:
40  DatabaseLogSink(DBPtr database);
41 
42  virtual void log(const spdlog::details::log_msg &msg) override;
43 
44  virtual void flush() override
45  {
46  // Noop as writing to a SQL database is transactional.
47  }
48 
49  private:
51  std::string run_id_;
52 };
53 }
54 }
Leosac::DBPtr
std::shared_ptr< odb::database > DBPtr
Definition: db_fwd.hpp:31
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Tools::DatabaseLogSink
A custom sink that write LogEntry object to a SQLite database.
Definition: DatabaseLogSink.hpp:33
Leosac::Tools::DatabaseLogSink::log
virtual void log(const spdlog::details::log_msg &msg) override
Definition: DatabaseLogSink.cpp:40
db_fwd.hpp
Leosac::Tools::DatabaseLogSink::database_
DBPtr database_
Definition: DatabaseLogSink.hpp:50
Leosac::Tools::DatabaseLogSink::DatabaseLogSink
DatabaseLogSink(DBPtr database)
Construct a SQLite backed log sink.
Definition: DatabaseLogSink.cpp:31
Leosac::Tools::DatabaseLogSink::run_id_
std::string run_id_
Definition: DatabaseLogSink.hpp:51
Leosac::Tools::DatabaseLogSink::flush
virtual void flush() override
Definition: DatabaseLogSink.hpp:44