Logr 0.9.0

Logr 0.9.0

Paulius Gudonis 维护。



Logr 0.9.0

  • 作者:
  • Paulius Gudonis

Logr

build status platforms codecov documentation

使用 Swift 编写的用于 iOS 的简单日志库

特性

  • 推断日志消息标签
  • Swift 包管理器/Carthage/CocoaPods 集成
  • 高度可扩展
  • 同时向多个目标/目的地进行日志记录
  • 通过 ConsoleTarget 无需设置即可在控制台中记录
  • 通过 FileTarget 无需设置即可随文件记录
  • 纯 Swift 5
  • 可选的文件标题
  • 根据文件大小或时间范围自动归档文件

集成

Swift 包管理器

一旦设置了 Swift 包,请将以下内容添加到您的 Package.swift

dependencies: [
  .package(url: "https://github.com/nakkht/logr.git", exact: "0.9.0")
]

Carthage

使用 Carthage 将 Logr 添加到项目中,请将以下内容添加到您的 Cartfile

github "nakkht/logr" "0.9.0"

CocoaPods

要使用CocoaPods集成,请安装CocoaPods并在您的Podfile中包含以下内容

pod 'Logr', '~> 0.9.0'

用法

在您的AppDelegate.swift文件中添加

import Logr

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool的开始处,配置logr服务所需的目标

LogrService.init(with: Config(ConsoleTarget(), FileTarget()))

在生产中进行更深入的配置时,建议省略ConsoleTarget。例如

#if DEBUG
static let targets: [Target] = [ConsoleTarget(), FileTarget()]
#else
static let targets: [Target] = [FileTarget()]
#endif

static let config = Config(targets: targets)

LogrService.init(with: config)

设置的目标将在整个应用程序中使用。

要记录消息,只需在类的初始化器中创建一个Logr实例并开始记录即可。例如

import Logr

class ViewController: UIViewController {

    private let logr = Logr()

    func logDebug() {
        logr.debug("debug message to be logged")
    }
}

示例

示例项目可以通过打开Demo子文件夹中的Demo.workspace来访问。

文档

作者

许可证

此仓库遵循 Apache v2.0 许可协议。 在此找到它

Copyright 2020 Paulius Gudonis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   https://apache.ac.cn/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.