cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
logging_config.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
21
25
26namespace msgpack_rpc::config {
27
28namespace {
29
31constexpr auto LOGGING_CONFIG_DEFAULT_MAX_FILE_SIZE =
32 static_cast<std::size_t>(1024 * 1024); // 1 MiB.
33
35constexpr auto LOGGING_CONFIG_DEFAULT_MAX_FILES = static_cast<std::size_t>(5);
36
38constexpr auto LOGGING_CONFIG_DEFAULT_OUTPUT_LOG_LEVEL =
40
41} // namespace
42
44 : max_file_size_(LOGGING_CONFIG_DEFAULT_MAX_FILE_SIZE),
45 max_files_(LOGGING_CONFIG_DEFAULT_MAX_FILES),
46 output_log_level_(LOGGING_CONFIG_DEFAULT_OUTPUT_LOG_LEVEL) {}
47
48LoggingConfig& LoggingConfig::file_path(std::string_view value) {
49 file_path_ = value;
50 return *this;
51}
52
54 if (value <= 0U) {
55 throw MsgpackRPCException(StatusCode::INVALID_ARGUMENT,
56 "Maximum size of a file must be greater than 0.");
57 }
58 max_file_size_ = value;
59 return *this;
60}
61
63 if (value <= 0U) {
64 throw MsgpackRPCException(StatusCode::INVALID_ARGUMENT,
65 "Maximum number of files must be greater than 0.");
66 }
67 max_files_ = value;
68 return *this;
69}
70
72 switch (value) {
79 break;
80 default:
82 StatusCode::INVALID_ARGUMENT, "Invalid log level.");
83 }
84 output_log_level_ = value;
85 return *this;
86}
87
88std::string_view LoggingConfig::file_path() const noexcept {
89 return file_path_;
90}
91
92std::size_t LoggingConfig::max_file_size() const noexcept {
93 return max_file_size_;
94}
95
96std::size_t LoggingConfig::max_files() const noexcept { return max_files_; }
97
101
102} // namespace msgpack_rpc::config
Class of exceptions in cpp-msgpack-rpc library.
logging::LogLevel output_log_level() const noexcept
Get the log level to write logs.
std::size_t max_file_size_
Maximum size of a file.
std::string_view file_path() const noexcept
Get the file path.
std::size_t max_files_
Maximum number of files.
std::size_t max_files() const noexcept
Get the maximum number of files.
logging::LogLevel output_log_level_
Log level to write logs.
std::size_t max_file_size() const noexcept
Get the maximum size of a file.
Definition of LogLevel enumeration.
Definition of LoggingConfig class.
Definition of MsgpackRPCException class.
Namespace of configurations.
LogLevel
Enumeration of log levels.
Definition log_level.h:29
@ TRACE
Trace. (Internal operations to send and receive messages.)
Definition log_level.h:31
@ WARN
Warnings. (Unexpected conditions which don't stop operations.)
Definition log_level.h:40
@ INFO
Information. (Not used in this library.)
Definition log_level.h:37
@ CRITICAL
Critical. (Unexpected conditions which can stop all operations in communication.)
Definition log_level.h:46
@ ERROR
Error. (Unexpected conditions which stop some operations in communication.)
Definition log_level.h:43
@ DEBUG
Debug. (Log of messages, initialization and finalization of clients and servers.)
Definition log_level.h:34
Definition of StatusCode enumeration.