diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..6082673 --- /dev/null +++ b/.clang-format @@ -0,0 +1,78 @@ +# Generated from CLion C/C++ Code Style settings +BinPackParameters: false +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignArrayOfStructures: Left +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: true + AcrossComments: false + +AlignOperands: DontAlign +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: true +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakTemplateDeclarations: Yes +# 函数和返回类型分两行,方便阅读 +AlwaysBreakAfterReturnType: TopLevelDefinitions +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +ConstructorInitializerAllOnOneLineOrOnePerLine: true +BreakInheritanceList: BeforeColon +ColumnLimit: 120 +CompactNamespaces: false +ContinuationIndentWidth: 4 +EmptyLineBeforeAccessModifier: LogicalBlock +SeparateDefinitionBlocks: Always +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PointerAlignment: Right +ReflowComments: false +SortIncludes: CaseSensitive +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never +PenaltyIndentedWhitespace: 1 diff --git a/tile/base/log/channel.h b/tile/base/log/channel.h new file mode 100644 index 0000000..a020502 --- /dev/null +++ b/tile/base/log/channel.h @@ -0,0 +1,22 @@ +#ifndef TILE_BASE_LOG_CHANNEL_H +#define TILE_BASE_LOG_CHANNEL_H + +#pragma once + +#include "tile/base/config/configurable.h" +#include "tile/base/ref_ptr.h" + +namespace tile { +namespace log { +class Channel : public Configurable, public RefCounted { +public: + void SetProperty(const Slice &name, const Slice &value) override; + std::string GetProperty(const Slice &name) const override; + +protected: + ~Channel() override; +}; +}// namespace log +};// namespace tile + +#endif// TILE_BASE_LOG_CHANNEL_H diff --git a/tile/base/log/logger.h b/tile/base/log/logger.h new file mode 100644 index 0000000..047d3c2 --- /dev/null +++ b/tile/base/log/logger.h @@ -0,0 +1,11 @@ +#ifndef TILE_BASE_LOG_LOGGER_H +#define TILE_BASE_LOG_LOGGER_H + +#pragma once + +namespace tile { +namespace log { +class Logger {}; +}// namespace log +}// namespace tile +#endif// TILE_BASE_LOG_LOGGER_H diff --git a/tile/base/log/message.h b/tile/base/log/message.h new file mode 100644 index 0000000..4bd8355 --- /dev/null +++ b/tile/base/log/message.h @@ -0,0 +1,98 @@ +#ifndef TILE_BASE_LOG_MESSAGE_H +#define TILE_BASE_LOG_MESSAGE_H + +#pragma once +#include +#include +#include + +namespace tile { +namespace log { +class Message { +public: + typedef std::map StringMap; + + enum Priority { + kTrace = 0, + kDebug, + kInfo, + kNotice, + kWarning, + kError, + kCritical, + kFatal, + }; + + Message(); + Message(const Message &other); + Message(Message &&other) noexcept; + ~Message(); + + Message &operator=(const Message &other); + Message &operator=(Message &&other) noexcept; + void swap(Message &other); + + // getter + inline const std::string &text() { return text_; } + + inline const std::string &source() const { return source_; } + + inline Priority priority() const { return priority_; } + + inline const std::string &thread_name() const { return thread_name_; } + + inline std::uint64_t tid() const { return tid_; } + + inline std::uint64_t pid() const { return pid_; } + + inline const char *source_file() const { return source_file_; } + + inline int source_line() const { return source_line_; } + + // setter + inline void set_text(const std::string &text) { text_ = text; } + + inline void set_source(const std::string &source) { source_ = source; } + + inline void set_priority(Priority priority) { priority_ = priority; } + + inline void set_thread_name(const std::string &thread) { thread_name_ = thread; } + + inline void set_tid(std::uint64_t tid) { tid_ = tid; } + + inline void set_pid(std::uint64_t pid) { pid_ = pid; } + + inline void set_source_file(const char *source_file) { source_file_ = source_file; } + + inline void set_source_line(int source_line) { source_line_ = source_line; } + + // map + const std::string &Get(const std::string ¶m) const; + const std::string &Get(const std::string ¶m, const std::string &defult_value) const; + const StringMap &GetAll() const; + void Set(const std::string ¶m, const std::string &value); + const std::string &operator[](const std::string ¶m) const; + std::string &operator[](const std::string ¶m); + +private: + std::string text_; + std::string source_; + Priority priority_; + std::string thread_name_; + std::uint64_t tid_; + std::uint64_t pid_; + const char *source_file_; + int source_line_; + StringMap properties_; +}; + +inline void +swap(Message &lhs, Message &rhs) +{ + lhs.swap(rhs); +} +}// namespace log + +}// namespace tile + +#endif// TILE_BASE_LOG_MESSAGE_H