Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
Logger.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_LOGGER_H
4#define ICE_LOGGER_H
5
6#include "Config.h"
7
8#include <memory>
9#include <string>
10
11namespace Ice
12{
13 class Logger;
14
15 /// A shared pointer to a Logger.
16 using LoggerPtr = std::shared_ptr<Logger>;
17
18 /// Represents Ice's abstraction for logging and tracing. Applications can provide their own logger by
19 /// implementing this abstraction and setting a logger on the communicator.
20 /// @remark The Ice runtime calls #print, #trace, #warning and #error from contexts where exceptions cannot be
21 /// handled, such as destructors and `noexcept` functions. Implementations of these functions must not throw
22 /// exceptions: a thrown exception can terminate the process.
23 /// @see InitializationData
24 /// @headerfile Ice/Ice.h
25 class ICE_API Logger
26 {
27 public:
28 virtual ~Logger();
29
30 // We use const std::string& and not std::string_view for the log messages because implementations commonly
31 // send the message to C APIs that require null-terminated strings.
32 // The message itself is also often constructed from a string produced by an ostringstream.
33
34 /// Prints a message.
35 /// The message is printed literally, without any decorations such as executable name or timestamp.
36 /// @param message The message to log.
37 /// @remark An implementation of this function must not throw exceptions.
38 virtual void print(const std::string& message) = 0;
39
40 /// Logs a trace message.
41 /// @param category The trace category.
42 /// @param message The trace message to log.
43 /// @remark An implementation of this function must not throw exceptions.
44 virtual void trace(const std::string& category, const std::string& message) = 0;
45
46 /// Logs a warning message.
47 /// @param message The warning message to log.
48 /// @remark An implementation of this function must not throw exceptions.
49 /// @see #error
50 virtual void warning(const std::string& message) = 0;
51
52 /// Logs an error message.
53 /// @param message The error message to log.
54 /// @remark An implementation of this function must not throw exceptions.
55 /// @see #warning
56 virtual void error(const std::string& message) = 0;
57
58 /// Returns this logger's prefix.
59 /// @return The prefix.
60 virtual std::string getPrefix() = 0;
61
62 /// Returns a clone of the logger with a new prefix.
63 /// @param prefix The new prefix for the logger.
64 /// @return A new logger instance with the specified prefix.
65 virtual LoggerPtr cloneWithPrefix(std::string prefix) = 0;
66 };
67}
68
69#endif
virtual void warning(const std::string &message)=0
Logs a warning message.
virtual void trace(const std::string &category, const std::string &message)=0
Logs a trace message.
virtual std::string getPrefix()=0
Returns this logger's prefix.
virtual void print(const std::string &message)=0
Prints a message.
virtual LoggerPtr cloneWithPrefix(std::string prefix)=0
Returns a clone of the logger with a new prefix.
virtual void error(const std::string &message)=0
Logs an error message.
Represents Ice's abstraction for logging and tracing.
Definition Logger.h:26
std::shared_ptr< Logger > LoggerPtr
A shared pointer to a Logger.
Definition Logger.h:16
The Ice RPC framework.
Definition SampleEvent.h:66