Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
Marco.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
23#pragma once
24
25#include <sese/record/Logger.h>
26#include <sese/text/Format.h>
27#include <sese/text/Util.h>
28#include <sese/thread/Thread.h>
29
30#ifdef SESE_C_LIKE_FORMAT
31#define __SESE_LOG(point_to_logger, level, format, ...) \
32 { \
33 char sese_tmp_buf[RECORD_OUTPUT_BUFFER]{0}; \
34 sese::text::snprintf(sese_tmp_buf, RECORD_OUTPUT_BUFFER, format, ##__VA_ARGS__); \
35 auto sese_tmp_time = sese::DateTime::now(); \
36 auto sese_tmp_event = std::make_shared<sese::record::Event>( \
37 sese_tmp_time, \
38 level, \
39 sese::Thread::getCurrentThreadName(), \
40 sese::Thread::getCurrentThreadId(), \
41 SESE_FILENAME, \
42 __LINE__, \
43 sese_tmp_buf \
44 ); \
45 point_to_logger->log(sese_tmp_event); \
46 }
47#else
48#define __SESE_LOG(point_to_logger, level, format, ...) \
49 { \
50 auto sese_tmp_msg = sese::text::fmt(format, ##__VA_ARGS__); \
51 auto sese_tmp_time = sese::DateTime::now(); \
52 auto sese_tmp_event = std::make_shared<sese::record::Event>( \
53 sese_tmp_time, \
54 level, \
55 sese::Thread::getCurrentThreadName(), \
56 sese::Thread::getCurrentThreadId(), \
57 SESE_FILENAME, \
58 __LINE__, \
59 sese_tmp_msg \
60 ); \
61 point_to_logger->log(sese_tmp_event); \
62 }
63#endif
64
65#define __SESE_RAW(point_to_logger, buffer, length) \
66 point_to_logger->dump(buffer, length); \
67 SESE_MARCO_END
68
69#define __SESE_EXCEPT(point_to_logger, e) \
70 e.printStacktrace(point_to_logger)
71
72#define __SESE_DEBUG(sese_tmp_logger, format, ...) \
73 __SESE_LOG(sese_tmp_logger, sese::record::Level::DEBUG, format, ##__VA_ARGS__) \
74 SESE_MARCO_END
75
76#define __SESE_INFO(sese_tmp_logger, format, ...) \
77 __SESE_LOG(sese_tmp_logger, sese::record::Level::INFO, format, ##__VA_ARGS__) \
78 SESE_MARCO_END
79
80#define __SESE_WARN(sese_tmp_logger, format, ...) \
81 __SESE_LOG(sese_tmp_logger, sese::record::Level::WARN, format, ##__VA_ARGS__) \
82 SESE_MARCO_END
83
84#define __SESE_ERROR(sese_tmp_logger, format, ...) \
85 __SESE_LOG(sese_tmp_logger, sese::record::Level::ERR, format, ##__VA_ARGS__) \
86 SESE_MARCO_END
87
88#define SESE_RAW(buffer, length) \
89 __SESE_RAW(sese::record::getLogger(), buffer, length)
90
91#define SESE_EXCEPT(e) __SESE_EXCEPT(sese::record::getLogger(), e)
92
93#define SESE_DEBUG(sese_tmp_format, ...) \
94 __SESE_LOG(sese::record::getLogger(), sese::record::Level::DEBUG, sese_tmp_format, ##__VA_ARGS__) \
95 SESE_MARCO_END
96
97#define SESE_INFO(sese_tmp_format, ...) \
98 __SESE_LOG(sese::record::getLogger(), sese::record::Level::INFO, sese_tmp_format, ##__VA_ARGS__) \
99 SESE_MARCO_END
100
101#define SESE_WARN(sese_tmp_format, ...) \
102 __SESE_LOG(sese::record::getLogger(), sese::record::Level::WARN, sese_tmp_format, ##__VA_ARGS__) \
103 SESE_MARCO_END
104
105#define SESE_ERROR(sese_tmp_format, ...) \
106 __SESE_LOG(sese::record::getLogger(), sese::record::Level::ERR, sese_tmp_format, ##__VA_ARGS__) \
107 SESE_MARCO_END