Microsoft Information Protection (MIP) SDK for C++: Reference 1.15
Doxygen-generated documentation for MIP SDK written in C++
Loading...
Searching...
No Matches
logger_delegate.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) Microsoft Corporation.
4 * All rights reserved.
5 *
6 * This code is licensed under the MIT License.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files(the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * 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 THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 *
26 */
27/**
28 * @brief A file containing the LoggerDelegate class to be used to override MIP
29 * logger
30 *
31 * @file logger_delegate.h
32 */
33
34
35#ifndef API_MIP_LOGGER_DELEGATE_H_
36#define API_MIP_LOGGER_DELEGATE_H_
37
38#include <memory>
39#include <string>
40
42#include "mip/mip_namespace.h"
43
44MIP_NAMESPACE_BEGIN
45
46/**
47 * @brief A class that defines the interface to the MIP SDK logger.
48 */
50public:
51 /**
52 * @brief Initialize the logger.
53 *
54 * @param storagePath the path to the location where persistent state, including logs, may be stored.
55 */
56 virtual void Init(const std::string& storagePath) = 0;
57 /**
58 * @brief Flush the logger
59 */
60 virtual void Flush() = 0;
61 /**
62 * @brief Write a log statement to log file
63 *
64 * @param level the log level for the log statement.
65 * @param message the message for the log statement.
66 * @param function the function name for the log statement.
67 * @param file the file name where log statement was generated.
68 * @param line the line number where the log statement was generated.
69 */
70 virtual void WriteToLog (
71 const LogLevel level,
72 const std::string& message,
73 const std::string& function,
74 const std::string& file,
75 const int32_t line) = 0;
76
77 /**
78 * @brief Write a log statement to log file with a context. Override this function to handle the context
79 *
80 * @param level the log level for the log statement.
81 * @param message the message for the log statement.
82 * @param function the function name for the log statement.
83 * @param file the file name where log statement was generated.
84 * @param line the line number where the log statement was generated.
85 * @param context Client context that was passed into the call that generated this log message
86 */
87 virtual void WriteToLogWithContext (
88 const LogLevel level,
89 const std::string& message,
90 const std::string& function,
91 const std::string& file,
92 const int32_t line,
93 const std::shared_ptr<void>& /*context*/) {
94 WriteToLog(level, message, function, file, line);
95 }
96
97 /**
98 * @brief Write a log statement to a log
99 *
100 * @param logMessage The log message data containing the logging information
101 */
102 virtual void WriteToLogWithLogMessage(const LogMessageData& logMessage) {
104 logMessage.GetLevel(),
105 logMessage.GetLogMessage(),
106 logMessage.GetFunction(),
107 logMessage.GetFile(),
108 logMessage.GetLine(),
109 logMessage.GetContext());
110 }
111
112 /** @cond DOXYGEN_HIDE */
113 virtual ~LoggerDelegate() {}
114protected:
115 LoggerDelegate() {}
116 /** @endcond */
117};
118
119MIP_NAMESPACE_END
120#endif // API_MIP_LOGGER_DELEGATE_H_
121
A class that stores log messages.
const std::shared_ptr< void > & GetContext() const
The logger context for the log statement.
const std::string & GetLogMessage() const
The message for the log statement.
const std::string & GetFile() const
The file name for the log statement.
const std::string & GetFunction() const
The function name for the log statement.
LogLevel GetLevel() const
The log level for the log statement.
int32_t GetLine() const
The line number for the log statement.
A class that defines the interface to the MIP SDK logger.
virtual void WriteToLogWithContext(const LogLevel level, const std::string &message, const std::string &function, const std::string &file, const int32_t line, const std::shared_ptr< void > &)
Write a log statement to log file with a context.
virtual void Flush()=0
Flush the logger.
virtual void WriteToLog(const LogLevel level, const std::string &message, const std::string &function, const std::string &file, const int32_t line)=0
Write a log statement to log file.
virtual void WriteToLogWithLogMessage(const LogMessageData &logMessage)
Write a log statement to a log.
virtual void Init(const std::string &storagePath)=0
Initialize the logger.
Contains the LogMessageData class for logging.
LogLevel
Different log levels used across the MIP SDK.
MIP namespace macros.