Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
Logger.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
21#pragma once
22
23#include "sese/Config.h"
26#include "sese/record/Event.h"
28
29#include <memory>
30#include <vector>
31
32#ifdef _WIN32
33#pragma warning(disable : 4251)
34#endif
35
36namespace sese::record {
37
39class LoggerInitiateTask final : public InitiateTask {
40public:
41 LoggerInitiateTask() : InitiateTask(__FUNCTION__) {}
42
43 int32_t init() noexcept override;
44 int32_t destroy() noexcept override;
45};
46
47class ConsoleAppender;
48
52class Logger {
53public:
55 typedef std::shared_ptr<Logger> Ptr;
56
58 Logger() noexcept;
59
60 virtual ~Logger() noexcept = default;
61
66 void addAppender(const AbstractAppender::Ptr &appender) noexcept;
67
72 void removeAppender(const AbstractAppender::Ptr &appender) noexcept;
73
78 virtual void log(const Event::Ptr &event) noexcept;
79
85 virtual void dump(const void *buffer, size_t length) noexcept;
86
87protected:
88 std::shared_ptr<AbstractFormatter> formatter;
89 std::shared_ptr<ConsoleAppender> builtInAppender;
90 std::vector<AbstractAppender::Ptr> appenderVector;
91
92public:
95 static void addGlobalLoggerAppender(const AbstractAppender::Ptr &appender) noexcept;
96
99 static void removeGlobalLoggerAppender(const AbstractAppender::Ptr &appender) noexcept;
100};
101
106extern record::Logger *getLogger() noexcept;
107} // namespace sese::record