Ice 3.9
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 virtual void print(const std::string& message) = 0;
38
39 /// Logs a trace message.
40 /// @param category The trace category.
41 /// @param message The trace message to log.
42 virtual void trace(const std::string& category, const std::string& message) = 0;
43
44 /// Logs a warning message.
45 /// @param message The warning message to log.
46 /// @see #error
47 virtual void warning(const std::string& message) = 0;
48
49 /// Logs an error message.
50 /// @param message The error message to log.
51 /// @see #warning
52 virtual void error(const std::string& message) = 0;
53
54 /// Returns this logger's prefix.
55 /// @return The prefix.
56 virtual std::string getPrefix() = 0;
57
58 /// Returns a clone of the logger with a new prefix.
59 /// @param prefix The new prefix for the logger.
60 /// @return A new logger instance with the specified prefix.
61 virtual LoggerPtr cloneWithPrefix(std::string prefix) = 0;
62 };
63}
64
65#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:60