RavEngine
Loading...
Searching...
No Matches
log.h
1
//----------------------------------------------------------------------------//
2
// //
3
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4
// and distributed under the MIT License (MIT). //
5
// //
6
// Copyright (c) Guillaume Blanc //
7
// //
8
// Permission is hereby granted, free of charge, to any person obtaining a //
9
// copy of this software and associated documentation files (the "Software"), //
10
// to deal in the Software without restriction, including without limitation //
11
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12
// and/or sell copies of the Software, and to permit persons to whom the //
13
// Software is furnished to do so, subject to the following conditions: //
14
// //
15
// The above copyright notice and this permission notice shall be included in //
16
// all copies or substantial portions of the Software. //
17
// //
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24
// DEALINGS IN THE SOFTWARE. //
25
// //
26
//----------------------------------------------------------------------------//
27
28
#ifndef OZZ_OZZ_BASE_LOG_H_
29
#define OZZ_OZZ_BASE_LOG_H_
30
31
#include <iostream>
32
33
// MSVC includes <cstring> from <iostream> but not gcc.
34
// So it is included here to ensure a portable behavior.
35
#include <cstring>
36
37
#include "platform.h"
38
39
// Proposes a logging interface that redirects logs to std::cout, clog and cerr
40
// output streams. This interface adds a logging level functionality (kSilent,
41
// kStandard, kVerbose) to the std API, which can be set using
42
// ozz::log::GetLevel function.
43
// Usage conforms to std stream usage: ozz::log::Log() << "something to log."...
44
45
namespace
ozz {
46
namespace
log
{
47
48
enum
Level {
49
kSilent,
// No output at all, even errors are muted.
50
kStandard,
// Default output level.
51
kVerbose,
// Most verbose output level.
52
};
53
54
// Sets the global logging level.
55
OZZ_BASE_DLL Level SetLevel(Level _level);
56
57
// Gets the global logging level.
58
OZZ_BASE_DLL Level GetLevel();
59
60
// Implements logging base class.
61
// This class is not intended to be used publicly, it is derived by user
62
// classes LogV, Log, Out, Err...
63
// Forwards ostream::operator << to a standard ostream or a silent
64
// ostringstream according to the logging level at construction time.
65
class
OZZ_BASE_DLL
Logger
{
66
public
:
67
// Forwards ostream::operator << for any type.
68
template
<
typename
_T>
69
std::ostream& operator<<(
const
_T& _t) {
70
return
stream_ << _t;
71
}
72
// Forwards ostream::operator << for modifiers.
73
std::ostream& operator<<(std::ostream& (*_Pfn)(std::ostream&)) {
74
return
((*_Pfn)(stream_));
75
}
76
// Implicit cast operator.
77
operator
std::ostream&()
const
{
return
stream_; }
78
79
// Explicit cast function.
80
std::ostream& stream()
const
{
return
stream_; }
81
82
protected
:
83
// Specifies the global stream and the output level.
84
// Logging levels allows to select _stream or a "silent" stream according to
85
// the current global logging level.
86
Logger
(std::ostream& _stream, Level _level);
87
88
// Destructor, deletes the internal "silent" stream.
89
~Logger
();
90
91
private
:
92
// Disables copy and assignment.
93
Logger
(
const
Logger
&);
94
void
operator=(
Logger
&);
95
96
// Selected output stream.
97
std::ostream& stream_;
98
99
// Stores whether the stream is local one, in which case it must be deleted
100
// in the destructor.
101
bool
local_stream_;
102
};
103
104
// Logs verbose output to the standard error stream (std::clog).
105
// Enabled if logging level is Verbose.
106
class
OZZ_BASE_DLL
LogV
:
public
Logger
{
107
public
:
108
LogV
();
109
};
110
111
// Logs output to the standard error stream (std::clog).
112
// Enabled if logging level is not Silent.
113
class
OZZ_BASE_DLL
Log
:
public
Logger
{
114
public
:
115
Log
();
116
};
117
118
// Logs output to the standard output (std::cout).
119
// Enabled if logging level is not Silent.
120
class
OZZ_BASE_DLL
Out
:
public
Logger
{
121
public
:
122
Out
();
123
};
124
125
// Logs error to the standard error stream (std::cerr).
126
// Enabled if logging level is not Silent.
127
class
OZZ_BASE_DLL
Err
:
public
Logger
{
128
public
:
129
Err
();
130
};
131
132
// RAII helper that modifies float logging precision, and restores default
133
// settings when exiting scope.
134
// User is reponsible for making sure stream still exist upon RAII destruction.
135
// See std::setprecision() for more details.
136
class
OZZ_BASE_DLL
FloatPrecision
{
137
public
:
138
FloatPrecision
(
const
Logger
& _logger,
int
_precision);
139
~FloatPrecision
();
140
141
private
:
142
FloatPrecision
(
FloatPrecision
const
&);
143
void
operator=(
FloatPrecision
const
&);
144
145
// Original precision and format.
146
const
std::streamsize precision_;
147
const
std::ios_base::fmtflags format_;
148
149
// Stream on which original precision must be restored.
150
std::ostream& stream_;
151
};
152
}
// namespace log
153
}
// namespace ozz
154
#endif
// OZZ_OZZ_BASE_LOG_H_
ozz::log::Err
Definition
log.h:127
ozz::log::FloatPrecision
Definition
log.h:136
ozz::log::LogV
Definition
log.h:106
ozz::log::Log
Definition
log.h:113
ozz::log::Logger
Definition
log.h:65
ozz::log::Out
Definition
log.h:120
glm::log
GLM_FUNC_QUALIFIER vec< L, T, Q > log(vec< L, T, Q > const &x)
Definition
func_exponential.inl:88
RavEngine
deps
ozz-animation
include
ozz
base
log.h
Generated by
1.9.8