FelinePine

FelinePine

类型范围内的分类日志记录。

SwiftPM Twitter GitHub GitHub issues GitHub Workflow Status

Codecov CodeFactor Grade codebeat badge Code Climate maintainability Code Climate technical debt Code Climate issues Reviewed by Hound

目录

简介

FelinePine 提供了一个易于使用的 API,用于在你的架构中设置日志记录和日志类别。

要求

Apple 平台

Linux

安装

使用 Swift Package Manager 通过仓库 URL 安装此库

https://github.com/brightdigit/FelinePine.git

使用最高至 1.0.0 的版本。

用法

快速入门

创建一个定义类别的 LoggingSystem

public enum BushelLogging: LoggingSystem {
  public enum Category: String, CaseIterable {
    case library
    case data
    case view
    case machine
    case application
    case observation
    case market
  }
}

内部的 Category 枚举必须具有 RawType 类型为 String。 此外,如果你希望利用自动创建的 Logger 对象,那么你也应该实现 CaseIterable

现在在任何类型中使用你的新 LoggingSystem

  1. 实现 FelinePine
  2. 定义你的 LoggingSystem
  3. 定义 LoggingSystem.Category
internal struct VirtualMachine: Loggable {
  internal typealias LoggingSystemType = BushelLogging

  internal static let loggingCategory: BushelLogging.Category = .machine
  
  func run () {
    Self.logger.debug("Starting Run")
    ...
  }
  ...
}

使用 Loggable 类型

你可以通过使用 Loggable 协议来创建一个在你的整个代码库中使用的协议来简化操作

public protocol BushelLoggable: FelinePine.Loggable where Self.LoggingSystemType == BushelLogging {}

现在你可以简单地使用新的 Loggable 类型

internal struct VirtualMachine: BushelLoggable {
  internal static let loggingCategory: BushelLogging.Category = .machine
  
  func run () {
    Self.logger.debug("Starting Run")
    ...
  }
}

更多文档

更多文档可在 Swift Package Index 上找到。

许可证

此代码是在 MIT 许可下分发的。 有关更多信息,请参见 LICENSE 文件。