NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
SimpleLogger.h
Go to the documentation of this file.
1 /*
2 * SPDX-FileCopyrightText: Copyright (c) 2020-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: MIT
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23 
25 #ifndef NVNEURAL_SIMPLELOGGER_H
26 #define NVNEURAL_SIMPLELOGGER_H
27 
28 #include <nvneural/CoreTypes.h>
29 #include <nvneural/CoreHelpers.h>
30 
31 #include <cstdarg>
32 #include <iostream>
33 
34 namespace nvneural {
35 
42  nvneural::refobj::Implements<nvneural::ILogger>>
43 {
44 public:
48  explicit SimpleLogger(VerbosityLevel verbosity);
49 
55  void setVerbosity(VerbosityLevel verbosity);
56 
64  void redirectAllOutput(std::ostream& destination);
65 
66  // ILogger implementations
67 
69  VerbosityLevel verbosity() const noexcept final;
70 
72  nvneural::NeuralResult log(VerbosityLevel verbosity, const char* format, ...) noexcept final;
73 
75  nvneural::NeuralResult logWarning(VerbosityLevel verbosity, const char* format, ...) noexcept final;
76 
78  nvneural::NeuralResult logError(VerbosityLevel verbosity, const char* format, ...) noexcept final;
79 
80 private:
81  VerbosityLevel m_verbosity = 0;
82  std::ostream* m_normalDestination = &std::cout;
83  std::ostream* m_severeDestination = &std::cerr;
84 
85  nvneural::NeuralResult logImpl(VerbosityLevel verbosity, std::ostream& streamOut, const char* prefix, const char* format, va_list formatArgs) noexcept;
86 
87  static nvneural::NeuralResult writeFormattedLog(std::ostream& streamOut, const char* prefix, char* formattedMessage);
88 };
89 
90 } // namespace nvneural
91 
92 #endif // NVNEURAL_SIMPLELOGGER_H
Common helper classes and template function implementations.
Fundamental NvNeural data types are declared here.
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:275
SimpleLogger is a basic ILogger implementation that displays to stdout.
Definition: SimpleLogger.h:43
void setVerbosity(VerbosityLevel verbosity)
Sets the new verbosity threshold for the logger.
Definition: SimpleLogger.cpp:36
nvneural::NeuralResult logError(VerbosityLevel verbosity, const char *format,...) noexcept final
Logs an error message.
Definition: SimpleLogger.cpp:70
nvneural::NeuralResult logWarning(VerbosityLevel verbosity, const char *format,...) noexcept final
Logs a warning message.
Definition: SimpleLogger.cpp:61
nvneural::NeuralResult log(VerbosityLevel verbosity, const char *format,...) noexcept final
Logs an informational message.
Definition: SimpleLogger.cpp:52
void redirectAllOutput(std::ostream &destination)
Redirects future logger output to a new C++ ostream object.
Definition: SimpleLogger.cpp:41
VerbosityLevel verbosity() const noexcept final
Retrieves the current verbosity level.
Definition: SimpleLogger.cpp:47
SimpleLogger(VerbosityLevel verbosity)
Creates a SimpleLogger with a default verbosity level.
Definition: SimpleLogger.cpp:31
Parameterized base class implementing common IRefObject operations.
Definition: RefObject.h:336