Develop Biology
The language of life
Writer.cpp
Go to the documentation of this file.
1/*
2 * This file is a part of the Biology project by eons LLC.
3 * Biology (aka Develop Biology) is a framework for approaching software
4 * development from a natural sciences perspective.
5 *
6 * Copyright (C) 2021 Séon O'Shannon & eons LLC
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include "bio/log/Writer.h"
23#include "bio/log/Engine.h"
25
26#include <stdarg.h>
27
28namespace bio {
29namespace log {
30
32 :
33 physical::Class< Writer >(this),
34 physical::Filterable(filter::Default()),
35 m_logEngine(NULL)
36{
37
38}
39
41 Engine* logEngine,
42 Filter filter
43)
44 :
45 physical::Class< Writer >(this),
46 physical::Filterable(filter::Default()),
47 m_logEngine(logEngine)
48{
49
50}
51
53{
54
55}
56
58{
59 m_logEngine = logEngine;
60}
61
63{
64 return m_logEngine;
65}
66
68{
69 return m_logEngine;
70}
71
73{
74 return m_logEngine != NULL;
75}
76
78 Level level,
79 const char* format,
80 ...
81) const
82{
83
84 BIO_SANITIZE(m_logEngine, ,
85 return);
86
87 //Check if filter is on
90 level
91 ), ,
92 return);
93
94 va_list args;
95 va_start(args,
96 format);
97 m_logEngine->Log(
99 level,
100 format,
101 args
102 );
103 va_end(args);
104}
105
107 Filter filter,
108 Level level,
109 const char* format,
110 ...
111) const
112{
113 BIO_SANITIZE(m_logEngine, ,
114 return);
115
116 va_list args;
117 va_start(args,
118 format);
119 m_logEngine->Log(
120 filter,
121 level,
122 format,
123 args
124 );
125 va_end(args);
126}
127
129{
130 if (args.size() == 2)
131 {
132 if (args[1].Is(m_logEngine))
133 {
134 m_logEngine = args[1];
135 }
136 args.pop_back();
137 }
138 if (args.size() == 1 && args[0].Is< Filter >())
139 {
140 Filterable::InitializeImplementation(args);
141 }
142}
143
144} //log namespace
145} //bio namespace
#define BIO_SANITIZE_AT_SAFETY_LEVEL_2(test, success, failure)
#define BIO_SANITIZE(test, success, failure)
bool FilterPass(Filter filter, Level level) const
Definition: Engine.cpp:108
void Log(Filter filter, Level level, const char *format, va_list args)
Definition: Engine.cpp:50
virtual ~Writer()
Definition: Writer.cpp:52
Engine * GetLogEngine()
Definition: Writer.cpp:62
Writer(Engine *logEngine, Filter logFilter)
Definition: Writer.cpp:31
virtual void SetLogEngine(Engine *logEngine)
Definition: Writer.cpp:57
void Log(Level level, const char *format,...) const
Definition: Writer.cpp:77
virtual void InitializeImplementation(ByteStreams args)
Definition: Writer.cpp:128
void ExternalLog(Filter logFilter, Level level, const char *format,...) const
Definition: Writer.cpp:106
bool HasLogEngine() const
Definition: Writer.cpp:72
Filter Default()
Definition: Cell.h:31
std::vector< ByteStream > ByteStreams
Definition: Types.h:52