Couchbase Lite C++
Couchbase Lite C++ API
Loading...
Searching...
No Matches
LogSinks.hh
Go to the documentation of this file.
1//
2// LogSinks.hh
3//
4// Copyright (c) 2025 Couchbase, Inc All rights reserved.
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//
18
19
20#pragma once
21#include "cbl/CBLLogSinks.h"
22#include "cbl++/Base.hh"
23#include "cbl/CBLDefaults.h"
24
26
27namespace cbl {
28
33
38
39 operator CBLConsoleLogSink() const {
40 return {(CBLLogLevel)(uint8_t)level, domains};
41 }
42 };
43
54
72
76 class LogSinks {
77 public:
80 static void setConsole(const ConsoleLogSink& sink) {
82 }
83
87 return fromCConfiguration(CBLLogSinks_Console());
88 }
89
93 static void setCustom(const CustomLogSink& sink) {
95 }
96
99 return fromCConfiguration(CBLLogSinks_CustomSink());
100 }
101
105 static void setFile(FileLogSink sink) {
107 (CBLLogLevel)(uint8_t)sink.level,
108 slice(sink.directory),
109 sink.maxKeptFiles,
110 sink.maxSize,
111 sink.usePlaintext
112 });
113 }
114
116 static FileLogSink file() {
117 return fromCConfiguration(CBLLogSinks_File());
118 }
119
120 private:
121 static ConsoleLogSink fromCConfiguration(const CBLConsoleLogSink& cSink) {
122 return { cSink.level, cSink.domains};
123 }
124
125 static CustomLogSink fromCConfiguration(const CBLCustomLogSink& cSink) {
126 return { cSink.level, cSink.callback, cSink.domains};
127 }
128
129 static FileLogSink fromCConfiguration(const CBLFileLogSink& cSink) {
130 return {
131 cSink.level,
132 std::string(cSink.directory),
133 cSink.maxKeptFiles,
134 cSink.maxSize,
135 cSink.usePlaintext
136 };
137 }
138 };
139}
140
#define _cbl_nullable
#define CBL_ASSUME_NONNULL_END
#define CBL_ASSUME_NONNULL_BEGIN
Controls where Couchbase Lite writes its log messages.
Definition LogSinks.hh:76
static void setConsole(const ConsoleLogSink &sink)
Sets the console log sink.
Definition LogSinks.hh:80
static ConsoleLogSink console()
Returns the current console log sink.
Definition LogSinks.hh:86
static FileLogSink file()
Returns the current file log sink.
Definition LogSinks.hh:116
static CustomLogSink custom()
Returns the current custom log sink.
Definition LogSinks.hh:98
static void setCustom(const CustomLogSink &sink)
Sets the custom log sink, whose callback receives each log message.
Definition LogSinks.hh:93
static void setFile(FileLogSink sink)
Sets the file log sink, which writes log messages to files in a directory.
Definition LogSinks.hh:105
void CBLLogSinks_SetCustom(CBLCustomLogSink sink)
CBLLogDomainMask
CBLCustomLogSink CBLLogSinks_CustomSink(void)
void CBLLogSinks_SetConsole(CBLConsoleLogSink sink)
void CBLLogSinks_SetFile(CBLFileLogSink sink)
CBLFileLogSink CBLLogSinks_File(void)
CBLLogDomain
CBLLogLevel
void(* CBLLogSinkCallback)(CBLLogDomain domain, CBLLogLevel level, FLString message)
CBLConsoleLogSink CBLLogSinks_Console(void)
kCBLLogNone
CBL_PUBLIC const bool kCBLDefaultFileLogSinkUsePlaintext
CBL_PUBLIC const size_t kCBLDefaultFileLogSinkMaxSize
CBL_PUBLIC const uint32_t kCBLDefaultFileLogSinkMaxKeptFiles
Definition Base.hh:46
fleece::slice slice
Convenience alias for fleece::slice, a non-owning view of a byte range.
Definition Base.hh:49
CBLLogDomainMask LogDomainMask
Definition LogSinks.hh:29
CBLLogLevel LogLevel
Definition LogSinks.hh:31
CBLLogDomain LogDomain
Definition LogSinks.hh:32
CBLLogSinkCallback LogSinkCallback
Definition LogSinks.hh:30
CBLLogLevel level
CBLLogDomainMask domains
CBLLogLevel level
CBLLogSinkCallback _cbl_nullable callback
CBLLogDomainMask domains
CBLLogLevel level
FLString directory
uint32_t maxKeptFiles
Console log sink configuration for logging to the console.
Definition LogSinks.hh:35
LogLevel level
The minimum level of message to write (Required).
Definition LogSinks.hh:36
LogDomainMask domains
Bitmask for enabled log domains. Use zero for all domains.
Definition LogSinks.hh:37
Custom log sink configuration for logging to a user-defined callback.
Definition LogSinks.hh:45
LogSinkCallback _Nullable callback
Custom log callback.
Definition LogSinks.hh:47
LogDomainMask domains
Bitmask for enabled log domains. Use zero for all domains.
Definition LogSinks.hh:48
LogLevel level
The minimum level of message to write (Required).
Definition LogSinks.hh:46
File log sink configuration for logging to files.
Definition LogSinks.hh:56
uint32_t maxKeptFiles
The maximum number of files to save per log level.
Definition LogSinks.hh:62
bool usePlaintext
Whether or not to log in plaintext as opposed to binary.
Definition LogSinks.hh:70
std::string directory
The directory where log files will be created (Required).
Definition LogSinks.hh:58
LogLevel level
The minimum level of message to write (Required).
Definition LogSinks.hh:57
size_t maxSize
The size in bytes at which a file will be rotated out (best effort).
Definition LogSinks.hh:66