Leosac  0.8.0
Open Source Access Control
LogEntry.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/database.hpp"
23 #include <boost/date_time/posix_time/posix_time.hpp>
24 #include <odb/core.hxx>
25 
26 namespace Leosac
27 {
28 namespace Tools
29 {
39 #pragma db object optimistic
40 class LogEntry
41 {
42  public:
43  LogEntry();
44 
45 #pragma db id auto
46  unsigned long id_;
47 
48 #pragma db not_null
49  boost::posix_time::ptime timestamp_;
50 
51 #pragma db not_null
52  std::string msg_;
53 
59 #pragma db not_null
60  std::string run_id_;
61 
62 #pragma db not_null
63  uint8_t level_;
64 
65 #pragma db not_null
66  size_t thread_id_;
67 
71  struct QueryResult
72  {
73  QueryResult() = default;
74  std::vector<LogEntry> entries;
75 
76  // metadata
77  size_t total;
78  size_t last;
79  size_t first;
80  };
81  static QueryResult retrieve(DBPtr database, int page_number, int page_size,
82  bool order_asc);
83 
84  private:
85  friend class odb::access;
86 
87 #pragma db version
88  const size_t version_;
89 };
90 
94 #pragma db view object(LogEntry)
95 struct LogView
96 {
97 #pragma db column("count(" + LogEntry::id_ + ")")
98  size_t count;
99 };
100 }
101 }
Leosac::Tools::LogEntry::thread_id_
size_t thread_id_
Definition: LogEntry.hpp:66
Leosac::Tools::LogEntry::access
friend class odb::access
Definition: LogEntry.hpp:85
Leosac::Tools::LogEntry::retrieve
static QueryResult retrieve(DBPtr database, int page_number, int page_size, bool order_asc)
Definition: LogEntry.cpp:61
Leosac::Tools::LogView::count
size_t count
Definition: LogEntry.hpp:98
database.hpp
Leosac::Tools::LogEntry::QueryResult::entries
std::vector< LogEntry > entries
Definition: LogEntry.hpp:74
Leosac::DBPtr
std::shared_ptr< odb::database > DBPtr
Definition: db_fwd.hpp:31
Leosac::Tools::LogView
SQL view over the LogEntry table.
Definition: LogEntry.hpp:95
Leosac::Tools::LogEntry::msg_
std::string msg_
Definition: LogEntry.hpp:52
Leosac::Tools::LogEntry::QueryResult::total
size_t total
Definition: LogEntry.hpp:77
Leosac::Tools::LogEntry::QueryResult::QueryResult
QueryResult()=default
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Tools::LogEntry::LogEntry
LogEntry()
Definition: LogEntry.cpp:32
Leosac::Tools::LogEntry::QueryResult::last
size_t last
Definition: LogEntry.hpp:78
Leosac::Tools::LogEntry::QueryResult
Structure holding the result for a retrieve() call.
Definition: LogEntry.hpp:71
Leosac::Tools::LogEntry::version_
const size_t version_
Definition: LogEntry.hpp:88
Leosac::Tools::LogEntry::level_
uint8_t level_
Definition: LogEntry.hpp:63
Leosac::Tools::LogEntry::id_
unsigned long id_
Definition: LogEntry.hpp:46
Leosac::Tools::LogEntry::timestamp_
boost::posix_time::ptime timestamp_
Definition: LogEntry.hpp:49
Leosac::Tools::LogEntry::run_id_
std::string run_id_
The run_id is generated when Leosac starts, and it is used to identify "runs" (ie if Leosac restarts)...
Definition: LogEntry.hpp:60
Leosac::Tools::LogEntry
A log entry.
Definition: LogEntry.hpp:40
Leosac::Tools::LogEntry::QueryResult::first
size_t first
Definition: LogEntry.hpp:79