Ion
|
Copyright 2016 Google Inc. More...
#include <functional>
#include <memory>
#include <sstream>
#include <string>
#include "ion/port/logging.h"
Go to the source code of this file.
Classes | |
class | ion::base::logging_internal::Logger |
This class is used for regular logging. More... | |
class | ion::base::logging_internal::NullLogger |
This class is used to disable logging, while still allowing for log messages to contain '<<' expressions. More... | |
class | ion::base::logging_internal::SingleLogger |
This class prints a message only the first time it is created for the passed file_name and line_number . More... | |
class | ion::base::logging_internal::ThrottledLogger |
This class prints a message only if the passed file_name and line_number has not printed a message in a certain amount of time. More... | |
Namespaces | |
ion | |
Copyright 2016 Google Inc. | |
ion::base | |
EnumHelper instantiations. These must be in the ion::base namespace. | |
ion::base::logging_internal | |
Internal logging implementation. | |
Macros | |
Internal LOG macro implementation | |
These macros implement Ion's LOG statement. Use the non-prefixed LOG macros in your code instead. | |
#define | ION_LOG(severity) |
Completely disable logging in production builds. More... | |
#define | ION_IGNORE_LOG(severity) ::ion::base::logging_internal::NullLogger().GetStream() |
Macro that ignores logging. More... | |
#define | ION_LOG_ONCE(severity) |
Macro that logs a message only once. More... | |
#define | ION_LOG_EVERY_N_SEC(severity, time) |
Macro that logs a message at most every N seconds. More... | |
Main logging macros | |
These macros log a message to the console in a platform-specific way. The severity argument determines the severity of the logging message. All versions of these macros use streaming syntax, like std::cerr. That is, you invoke them like: | |
#define | LOG(severity) ION_LOG(severity) |
Logs the streamed message unconditionally with a severity of severity . More... | |
#define | LOG_ONCE(severity) ION_LOG_ONCE(severity) |
Logs the streamed message once per process run with a severity of severity . More... | |
#define | LOG_EVERY_N_SEC(severity, time) ION_LOG_EVERY_N_SEC(severity, time) |
Logs the streamed message at most once every time seconds with a severity of severity . More... | |
#define | DLOG(severity) ION_IGNORE_LOG(severity) |
Same as LOG(severity), but only logs in debug mode. More... | |
#define | DLOG_ONCE(severity) ION_IGNORE_LOG(severity) |
Same as LOG_ONCE(severity), but only logs in debug mode. More... | |
#define | DLOG_EVERY_N_SEC(severity, time) ION_IGNORE_LOG(severity) |
Same as LOG_EVERY_N_SEC(severity, time), but only logs in debug mode. More... | |
Internal CHECK macro implementation | |
These macros implement Ion's CHECK and DCHECK statements. Use the non- prefixed CHECK and DCHECK macros in your code instead. | |
#define | ION_LOG_CHECK_MESSAGE(severity, check_type, expr) |
#define | ION_CHECK(expr) |
#define | ION_DCHECK(expr) |
ION_DCHECK is defined normally in debug builds. More... | |
#define | ION_CHECK_OP(op, val1, val2) |
#define | ION_DCHECK_OP(op, val1, val2) |
CHECK and DCHECK macros | |
These macros will assert that the value they are given satisfies some predicate (for CHECK, the expression must evaluate to true). If it does not, the process will be forcibly killed. In the DCHECK variants, the check will only be performed in debug mode.
| |
#define | CHECK(expr) ION_CHECK(expr) |
#define | CHECK_EQ(val1, val2) ION_CHECK_OP(==, val1, val2) |
#define | CHECK_NE(val1, val2) ION_CHECK_OP(!=, val1, val2) |
#define | CHECK_LE(val1, val2) ION_CHECK_OP(<=, val1, val2) |
#define | CHECK_LT(val1, val2) ION_CHECK_OP(<, val1, val2) |
#define | CHECK_GE(val1, val2) ION_CHECK_OP(>=, val1, val2) |
#define | CHECK_GT(val1, val2) ION_CHECK_OP(>, val1, val2) |
#define | DCHECK(expr) ION_DCHECK(expr) |
#define | DCHECK_EQ(val1, val2) ION_DCHECK_OP(==, val1, val2) |
#define | DCHECK_NE(val1, val2) ION_DCHECK_OP(!=, val1, val2) |
#define | DCHECK_LE(val1, val2) ION_DCHECK_OP(<=, val1, val2) |
#define | DCHECK_LT(val1, val2) ION_DCHECK_OP(<, val1, val2) |
#define | DCHECK_GE(val1, val2) ION_DCHECK_OP(>=, val1, val2) |
#define | DCHECK_GT(val1, val2) ION_DCHECK_OP(>, val1, val2) |
#define | CHECK_NOTNULL(val) |
Check that the input is not NULL. More... | |
Functions | |
void | ion::base::SetLogEntryWriter (port::LogEntryWriter *w) |
Public functions. More... | |
port::LogEntryWriter * | ion::base::GetLogEntryWriter () |
Returns the log-writer that messages are currently logged to. More... | |
port::LogEntryWriter * | ion::base::GetDefaultLogEntryWriter () |
Returns the log-writer that messages will be logged to if if another is not explicitly specified via SetLogEntryWriter(). More... | |
void | ion::base::SetBreakHandler (const std::function< void()> &break_handler) |
Sets a custom break handler that gets invoked by Logger::CheckMessage. More... | |
void | ion::base::RestoreDefaultBreakHandler () |
Restores the default break handler (port::BreakAndAbort). More... | |
template<typename T > | |
T & | ion::base::logging_internal::CheckNotNullCommon (const char *expr_string, T &t) |
Helpers for CHECK_NOTNULL(). More... | |
template<typename T > | |
T * | ion::base::logging_internal::CheckNotNull (const char *expr_string, T *t) |
template<typename T > | |
T & | ion::base::logging_internal::CheckNotNull (const char *expr_string, T &t) |
template<typename T > | |
const T & | ion::base::logging_internal::CheckNotNull (const char *expr_string, const T &t) |
This extra overload is needed to support non-const rvalues of non-pointer type. More... | |
Copyright 2016 Google Inc.
All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Macros for displaying logging messages and checking assertions. Logging and checking facilities are each available in fatal and non-fatal variants, and variants that log only in debug mode vs. always.
Definition in file logging.h.
#define CHECK | ( | expr | ) | ION_CHECK(expr) |
Definition at line 323 of file logging.h.
Referenced by ion::profile::TraceRecorder::AddTraceToTimelineNode(), ion::profile::CallTraceManager::GetArgType(), ion::gfx::Attribute::GetTypeByValue(), ion::gfx::Uniform::GetTypeByValue(), and Timeline::const_iterator::operator++().
#define CHECK_EQ | ( | val1, | |
val2 | |||
) | ION_CHECK_OP(==, val1, val2) |
#define CHECK_GE | ( | val1, | |
val2 | |||
) | ION_CHECK_OP(>=, val1, val2) |
#define CHECK_GT | ( | val1, | |
val2 | |||
) | ION_CHECK_OP(>, val1, val2) |
Definition at line 329 of file logging.h.
Referenced by ion::analytics::SampleMapping::SampleMapping().
#define CHECK_LE | ( | val1, | |
val2 | |||
) | ION_CHECK_OP(<=, val1, val2) |
#define CHECK_LT | ( | val1, | |
val2 | |||
) | ION_CHECK_OP(<, val1, val2) |
Definition at line 327 of file logging.h.
Referenced by ion::analytics::SampleMapping::SampleMapping().
#define CHECK_NE | ( | val1, | |
val2 | |||
) | ION_CHECK_OP(!=, val1, val2) |
#define CHECK_NOTNULL | ( | val | ) |
Check that the input is not NULL.
Unlike other CHECK macros, this one returns val, so it can be used in initializer lists. Outside initializers, prefer CHECK.
#define DCHECK | ( | expr | ) | ION_DCHECK(expr) |
Definition at line 331 of file logging.h.
Referenced by ion::profile::TraceRecorder::AddTraceToTimelineNode(), ion::math::AdjugateWithDeterminant(), ion::base::Allocatable::Allocatable(), ion::base::StlAllocator< T >::allocate(), ion::base::DataContainer::AllocatorDeleter(), ion::profile::TraceRecorder::AnnotateCurrentScopeAtTime(), ion::gfxutils::BufferToAttributeBinder< T >::Apply(), ion::gfx::Renderer::BindFramebuffer(), ion::gfx::BufferObject::BufferSubData::BufferSubData(), ion::gfxutils::BufferToAttributeBinder< T >::BufferToAttributeBinder(), ion::text::Builder::Build(), ion::text::OutlineBuilder::BuildVertexData(), ion::gfxutils::BuildWireframeIndexBuffer(), ion::text::Font::CacheSdfGrids(), ion::math::CofactorMatrix(), ion::gfx::Image::ComputeDataSize(), ion::base::DateTime::ComputeDateString(), ion::text::ComputeTextSize(), ion::base::DateTime::ComputeTimeString(), ion::profile::TraceRecorder::CreateTimeStampAtTime(), ion::base::internal_variant_utils::ManualConstructor< T15 >::Destroy(), ion::math::Determinant(), ion::profile::TraceRecorder::DumpTrace(), ion::profile::TraceRecorder::EnterTimeRange(), ion::math::Rotation< T >::GetAxisAndAngle(), ion::portgfx::Visual::GetCurrent(), ion::base::DateTime::GetDateTimeField(), ion::math::Rotation< T >::GetEulerAngles(), ion::text::Builder::GetFontImageTexture(), ion::base::CircularBuffer< uint32 >::GetItem(), ion::text::Font::GetMutableGlyphGridLocked(), ion::profile::CallTraceManager::GetNamedTraceRecorder(), ion::gfx::Image::GetNumComponentsForFormat(), ion::gfx::UniformHolder::GetUniformIndex(), ion::base::internal_variant_utils::ManualConstructor< T15 >::Init(), ion::base::internal_variant_utils::ManualConstructor< T15 >::InitArray(), ion::analytics::GpuPerformanceTester::InstanceCopy(), ion::math::LookAtMatrixFromDir(), ion::analytics::GpuPerformanceTester::MeasureBaseline(), ion::analytics::GpuPerformanceTester::MeasureMinViewportSpeed(), ion::analytics::GpuPerformanceTester::MeasurePerformance(), ion::analytics::GpuPerformanceTester::MeasureStateChanges(), ion::math::Normalize(), ion::base::SharedPtr< AllocationTracker >::operator*(), ion::base::SharedPtr< AllocationTracker >::operator->(), ion::math::VectorBase< Dimension, T >::operator[](), ion::math::OrthoInverseH(), ion::base::ZipAssetManager::RegisterAssetData(), ion::remote::HttpServer::RegisterHandler(), ion::gfx::Renderer::Renderer(), ion::gfx::StateTable::ResetValue(), ion::profile::ScopedFrameTracer::ScopedFrameTracer(), ion::profile::ScopedTracer::ScopedTracer(), ion::remote::HttpClient::Url::Set(), ion::gfx::ResourceHolder::SetResource(), ion::gfx::ShaderProgram::ShaderProgram(), ion::text::Builder::StoreGlyphVertices(), ion::portgfx::Visual::TeardownVisual(), ion::base::SpinMutex::Unlock(), ion::gfx::UpdateFromStateTable(), ion::gfx::UpdateSettingsInStateTable(), ion::gfx::UpdateStateTable(), ion::text::OutlineBuilder::UpdateUniforms(), ion::gfx::ResourceHolder::VectorField< T >::VectorField(), ion::profile::VSyncProfiler::VSyncProfiler(), ion::gfxutils::ResourceCallback< T >::~ResourceCallback(), ion::profile::ScopedFrameTracer::~ScopedFrameTracer(), ion::profile::ScopedTracer::~ScopedTracer(), ion::base::SpinMutex::~SpinMutex(), and ion::base::WeakReferent::~WeakReferent().
#define DCHECK_EQ | ( | val1, | |
val2 | |||
) | ION_DCHECK_OP(==, val1, val2) |
Definition at line 332 of file logging.h.
Referenced by ion::gfxutils::BuildWireframeIndexBuffer(), ion::portgfx::Visual::CreateVisualInShareGroup(), ion::gfx::CubeMapTexture::CubeMapTexture(), ion::portgfx::Visual::DestroyWrappingVisual(), ion::gfx::FramebufferObject::GetColorAttachment(), ion::portgfx::Visual::GetCurrent(), ion::gfx::AttributeArray::IsAttributeEnabled(), ion::base::MimeBase64EncodeString(), ion::math::Range1TWrapper< T, N >::operator[](), ion::base::ZipAssetManager::RegisterAssetData(), ion::gfx::FramebufferObject::SetColorAttachment(), ion::text::Font::SetFontMetrics(), ion::gfx::ResourceHolder::SetResource(), ion::gfx::TextureManager::TextureManager(), and ion::base::Shareable::~Shareable().
#define DCHECK_GE | ( | val1, | |
val2 | |||
) | ION_DCHECK_OP(>=, val1, val2) |
Definition at line 336 of file logging.h.
Referenced by ion::text::Font::AddGlyphsForAsciiCharacterRange(), ion::base::DateTime::ComputeDateString(), ion::base::DateTime::FromString(), ion::base::IndexMap< EnumType, uint32 >::GetOrderedIndex(), ion::gfx::TextureManager::GetTexture(), ion::math::LookAtMatrixFromDir(), ion::analytics::GpuPerformanceTester::MeasurePerformance(), ion::gfx::TextureManager::TextureManager(), ion::text::BasicBuilder::UpdateUniforms(), and ion::text::OutlineBuilder::UpdateUniforms().
#define DCHECK_GT | ( | val1, | |
val2 | |||
) | ION_DCHECK_OP(>, val1, val2) |
Definition at line 337 of file logging.h.
Referenced by ion::text::ComputeTransformData(), ion::base::IndexMap< EnumType, uint32 >::GetUnorderedIndex(), ion::profile::TraceRecorder::LeaveScopeAtTime(), ion::math::Range< Dimension, T >::SetMaxComponent(), and ion::math::Range< Dimension, T >::SetMinComponent().
#define DCHECK_LE | ( | val1, | |
val2 | |||
) | ION_DCHECK_OP(<=, val1, val2) |
Definition at line 334 of file logging.h.
Referenced by ion::text::Font::AddGlyphsForAsciiCharacterRange(), ion::math::AngleBetween(), ion::gfxutils::BuildRegularPolygonShape(), ion::base::DateTime::ComputeDateString(), ion::base::DateTime::FromString(), ion::base::IndexMap< EnumType, uint32 >::GetUnorderedIndex(), ion::math::PerspectiveMatrixInverse(), ion::math::Range< Dimension, T >::SetMaxComponent(), and ion::math::Range< Dimension, T >::SetMinComponent().
#define DCHECK_LT | ( | val1, | |
val2 | |||
) | ION_DCHECK_OP(<, val1, val2) |
Definition at line 335 of file logging.h.
Referenced by ion::profile::TraceRecorder::AddTraceToTimelineNode(), ion::profile::TraceRecorder::DumpStrings(), ion::gfx::TextureManager::GetTexture(), ion::gfx::TextureManager::GetUnit(), and ion::base::DateTime::operator+=().
#define DCHECK_NE | ( | val1, | |
val2 | |||
) | ION_DCHECK_OP(!=, val1, val2) |
Definition at line 333 of file logging.h.
Referenced by ion::profile::TraceRecorder::AnnotateCurrentScopeAtTime(), ion::base::DateTime::ComputeDateString(), and ion::math::Rotation< T >::GetAxisAndAngle().
#define DLOG | ( | severity | ) | ION_IGNORE_LOG(severity) |
Same as LOG(severity), but only logs in debug mode.
Definition at line 230 of file logging.h.
Referenced by ion::image::FlipImage(), ion::image::FlipImageHorizontally(), ion::base::ZipAssetManager::RegisterAssetData(), and ion::image::StraightAlphaFromPremultipliedAlpha().
#define DLOG_EVERY_N_SEC | ( | severity, | |
time | |||
) | ION_IGNORE_LOG(severity) |
Same as LOG_EVERY_N_SEC(severity, time), but only logs in debug mode.
#define DLOG_ONCE | ( | severity | ) | ION_IGNORE_LOG(severity) |
Same as LOG_ONCE(severity), but only logs in debug mode.
#define ION_CHECK | ( | expr | ) |
#define ION_CHECK_OP | ( | op, | |
val1, | |||
val2 | |||
) |
#define ION_DCHECK | ( | expr | ) |
ION_DCHECK is defined normally in debug builds.
In optimized and production builds, we still want to compile expr in order to avoid unused variable warnings and to ensure that expr is valid code.
We do not evaluate expr at runtime, though (the compiler optimizes it away), hence we also never use any strings that might get passed to ION_DCHECK using operator<< and we can discard them by passing them into a NullLogger. Using a NullLogger instead of a regular Logger results in fewer instructions after preprocessing, and increases the likelihood for small functions to be inlined in compilers that are sensitive to that (such as Visual C++).
An efficient way to achieve this is to let a call such as DCHECK(expr) << "foo"
to be expanded to (true) ? (void)(expr) : ::ion::base::logging_internal::NullLogger().GetStream() << "foo"
This ensures three things: (1) expr gets compiled, but its generated code gets thrown away. (2) Callers can still pass in a debug string that then gets thrown away. (3) The entire expression is a no-op.
Some toolchains do not support the ternary operator syntax since they require the second and third operand to be of the same type. Hence by default we use an if/else clause instead. Visual Studio seems to have a higher likelihood of inlining for small functions that use ION_DCHECKs if they expand to the ternary operator, so we use the ternary operator on Windows.
#define ION_DCHECK_OP | ( | op, | |
val1, | |||
val2 | |||
) |
#define ION_IGNORE_LOG | ( | severity | ) | ::ion::base::logging_internal::NullLogger().GetStream() |
#define ION_LOG | ( | severity | ) |
Completely disable logging in production builds.
Macro that actually causes logging to happen.
Definition at line 178 of file logging.h.
Referenced by ion::base::logging_internal::CheckNotNullCommon().
#define ION_LOG_CHECK_MESSAGE | ( | severity, | |
check_type, | |||
expr | |||
) |
#define ION_LOG_EVERY_N_SEC | ( | severity, | |
time | |||
) |
Macro that logs a message at most every N seconds.
#define ION_LOG_ONCE | ( | severity | ) |
Macro that logs a message only once.
#define LOG | ( | severity | ) | ION_LOG(severity) |
Logs the streamed message unconditionally with a severity of severity
.
Definition at line 216 of file logging.h.
Referenced by ion::gfx::ShaderInputRegistry::Add(), ion::gfx::ResourceHolder::VectorField< T >::Add(), ion::text::FontManager::AddFontFromZipasset(), ion::gfx::BufferObject::AddSpec(), ion::gfx::Shape::AddVertexRange(), ion::gfxutils::BufferToAttributeBinder< T >::AreBindingsPacked(), ion::gfxutils::Frame::Begin(), ion::text::Font::CacheSdfGrid(), ion::base::OnceFlag::CallChecked(), ion::gfx::ShaderInputRegistry::CheckInputsAreUnique(), ion::portgfx::Visual::CreateVisualInCurrentShareGroup(), ion::image::DownsampleImage2x(), ion::gfxutils::Frame::End(), ion::gfx::Texture::ExpectedDimensionsForMipmap(), ion::gfx::FramebufferObject::FramebufferObject(), ion::base::DateTime::FromString(), ion::gfx::GraphicsManager::GetCapabilityValue(), ion::base::DateTime::GetDateTimeField(), ion::portgfx::Visual::GetGlVersion(), ion::base::DataContainer::GetMutableData(), ion::profile::CallTraceManager::GetNamedTraceRecorder(), ion::gfx::BufferObject::GetSpec(), ion::gfx::Renderer::GetStateTable(), ion::gfx::ShaderInputRegistry::Include(), ion::portgfx::IsExtensionSupported(), ion::portgfx::Visual::MakeCurrent(), ion::gfx::Renderer::MapBufferObjectData(), ion::gfx::Renderer::MapBufferObjectDataRange(), ion::gfxprofile::GpuProfiler::PollGlTimerQueries(), ion::image::ResizeImage(), ion::gfx::Renderer::ResolveMultisampleFramebuffer(), ion::remote::HttpClient::Url::Set(), ion::gfx::ResourceHolder::Field< std::string >::Set(), ion::gfx::ShaderProgram::SetConcurrent(), ion::base::DateTime::SetDay(), ion::analytics::GpuPerformanceTester::SetEnables(), ion::base::DateTime::SetHour(), ion::gfx::CubeMapTexture::SetImage(), ion::gfx::Texture::SetImage(), ion::gfx::TextureBase::SetImmutableImage(), ion::base::DateTime::SetMinute(), ion::base::DateTime::SetMonth(), ion::gfx::TextureBase::SetMultisampling(), ion::base::DateTime::SetNanosecond(), ion::base::DateTime::SetSecond(), ion::gfx::TextureManager::SetUnitRange(), ion::gfx::Shape::SetVertexRange(), ion::base::DateTime::SetZoneHours(), ion::base::DateTime::SetZoneMinutes(), ion::base::FullAllocationTracker::TrackDeallocation(), ion::gfx::Renderer::UnmapBufferObjectData(), ion::profile::CallTraceManager::WriteFile(), ion::base::LogChecker::~LogChecker(), and ion::gfx::Renderer::~Renderer().
#define LOG_EVERY_N_SEC | ( | severity, | |
time | |||
) | ION_LOG_EVERY_N_SEC(severity, time) |
#define LOG_ONCE | ( | severity | ) | ION_LOG_ONCE(severity) |
Logs the streamed message once per process run with a severity of severity
.
Definition at line 219 of file logging.h.
Referenced by ion::profile::TraceRecorder::GetCurrentFrameNumber(), ion::profile::TraceRecorder::LeaveFrame(), and ion::profile::VSyncProfiler::RecordVSyncEvent().