Logr

build unit test platforms codecov code size documentation

iOS 平台的 Swift 简易日志库

特性

集成

Swift Package Manager

一旦 Swift 包设置完成,将以下内容添加到你的 Package.swift

dependencies: [
  .package(url: "https://github.com/nakkht/logr.git", exact: "0.11.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 2021 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.