cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
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
*/
20
#include "
msgpack_rpc/config/logging_config.h
"
21
22
#include "
msgpack_rpc/common/msgpack_rpc_exception.h
"
23
#include "
msgpack_rpc/common/status_code.h
"
24
#include "
msgpack_rpc/logging/log_level.h
"
25
26
namespace
msgpack_rpc::config
{
27
28
namespace
{
29
31
constexpr
auto
LOGGING_CONFIG_DEFAULT_MAX_FILE_SIZE =
32
static_cast<
std::size_t
>
(1024 * 1024);
// 1 MiB.
33
35
constexpr
auto
LOGGING_CONFIG_DEFAULT_MAX_FILES =
static_cast<
std::size_t
>
(5);
36
38
constexpr
auto
LOGGING_CONFIG_DEFAULT_OUTPUT_LOG_LEVEL =
39
logging::LogLevel::INFO
;
40
41
}
// namespace
42
43
LoggingConfig::LoggingConfig
()
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
48
LoggingConfig
&
LoggingConfig::file_path
(std::string_view value) {
49
file_path_
= value;
50
return
*
this
;
51
}
52
53
LoggingConfig
&
LoggingConfig::max_file_size
(std::size_t value) {
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
62
LoggingConfig
&
LoggingConfig::max_files
(std::size_t value) {
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
71
LoggingConfig
&
LoggingConfig::output_log_level
(
logging::LogLevel
value) {
72
switch
(value) {
73
case
logging::LogLevel::TRACE
:
74
case
logging::LogLevel::DEBUG
:
75
case
logging::LogLevel::INFO
:
76
case
logging::LogLevel::WARN
:
77
case
logging::LogLevel::ERROR
:
78
case
logging::LogLevel::CRITICAL
:
79
break
;
80
default
:
81
throw
MsgpackRPCException
(
82
StatusCode::INVALID_ARGUMENT,
"Invalid log level."
);
83
}
84
output_log_level_
= value;
85
return
*
this
;
86
}
87
88
std::string_view
LoggingConfig::file_path
() const noexcept {
89
return
file_path_
;
90
}
91
92
std::size_t
LoggingConfig::max_file_size
() const noexcept {
93
return
max_file_size_
;
94
}
95
96
std::size_t
LoggingConfig::max_files
() const noexcept {
return
max_files_
; }
97
98
logging::LogLevel
LoggingConfig::output_log_level
() const noexcept {
99
return
output_log_level_
;
100
}
101
102
}
// namespace msgpack_rpc::config
msgpack_rpc::MsgpackRPCException
Class of exceptions in cpp-msgpack-rpc library.
Definition
msgpack_rpc_exception.h:35
msgpack_rpc::config::LoggingConfig::output_log_level
logging::LogLevel output_log_level() const noexcept
Get the log level to write logs.
Definition
logging_config.cpp:98
msgpack_rpc::config::LoggingConfig::max_file_size_
std::size_t max_file_size_
Maximum size of a file.
Definition
logging_config.h:110
msgpack_rpc::config::LoggingConfig::file_path_
std::string file_path_
File path.
Definition
logging_config.h:107
msgpack_rpc::config::LoggingConfig::file_path
std::string_view file_path() const noexcept
Get the file path.
Definition
logging_config.cpp:88
msgpack_rpc::config::LoggingConfig::max_files_
std::size_t max_files_
Maximum number of files.
Definition
logging_config.h:113
msgpack_rpc::config::LoggingConfig::max_files
std::size_t max_files() const noexcept
Get the maximum number of files.
Definition
logging_config.cpp:96
msgpack_rpc::config::LoggingConfig::LoggingConfig
LoggingConfig()
Constructor.
Definition
logging_config.cpp:43
msgpack_rpc::config::LoggingConfig::output_log_level_
logging::LogLevel output_log_level_
Log level to write logs.
Definition
logging_config.h:116
msgpack_rpc::config::LoggingConfig::max_file_size
std::size_t max_file_size() const noexcept
Get the maximum size of a file.
Definition
logging_config.cpp:92
log_level.h
Definition of LogLevel enumeration.
logging_config.h
Definition of LoggingConfig class.
msgpack_rpc_exception.h
Definition of MsgpackRPCException class.
msgpack_rpc::config
Namespace of configurations.
Definition
client_config.h:32
msgpack_rpc::logging::LogLevel
LogLevel
Enumeration of log levels.
Definition
log_level.h:29
msgpack_rpc::logging::LogLevel::TRACE
@ TRACE
Trace. (Internal operations to send and receive messages.).
Definition
log_level.h:31
msgpack_rpc::logging::LogLevel::WARN
@ WARN
Warnings. (Unexpected conditions which don't stop operations.).
Definition
log_level.h:40
msgpack_rpc::logging::LogLevel::INFO
@ INFO
Information. (Not used in this library.).
Definition
log_level.h:37
msgpack_rpc::logging::LogLevel::CRITICAL
@ CRITICAL
Critical. (Unexpected conditions which can stop all operations in communication.).
Definition
log_level.h:46
msgpack_rpc::logging::LogLevel::ERROR
@ ERROR
Error. (Unexpected conditions which stop some operations in communication.).
Definition
log_level.h:43
msgpack_rpc::logging::LogLevel::DEBUG
@ DEBUG
Debug. (Log of messages, initialization and finalization of clients and servers.).
Definition
log_level.h:34
status_code.h
Definition of StatusCode enumeration.
src
msgpack_rpc
config
logging_config.cpp
Generated on
for cpp-msgpack-rpc by
1.18.0