Swiftpack.co - genedelisa/GDLog as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by genedelisa.
genedelisa/GDLog 0.1.1
Wrapper for OSLog
⭐️ 0
🕓 4 years ago
.package(url: "https://github.com/genedelisa/GDLog.git", from: "0.1.1")

GDLog

Platforms License

Swift Package Manager Carthage compatible CocoaPods compatible

Travis

Swift 5

Platforms iOS Platforms macOS Platforms tvOS Platforms watchOS

Sponsors Twitter @GeneDeLisaDev

Yet another logger for Swift.

This uses Apple's Unified Logging OSLog - and NSLog as a fallback, so it's essentially a façade. I think this makes OSLog easier to use in Swift since you can use string interpolation.

I renamed this from GDLog since there is already a Cocoapod with that name.

Requirements

  • iOS 10.0+ / Mac OS X 10.12+ / tvOS 10.0+ / watchOS 3.0+
  • Xcode 9.0+

Installation

### Swift Package Manager

To use GDLog as a [Swift Package Manager](https://swift.org/package-manager/) package just add the following in your Package.swift file.

``` swift
import PackageDescription

let package = Package(
name: "GDLog",
dependencies: [
.Package(url: "https://github.com/genedelisa/GDLog.git", "0.0.1")
]
)

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate GDLog into your project manually.

Git Submodules

  • Open up Terminal, cd into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:
$ git init
  • Add GDLog as a git submodule by running the following command:
$ git submodule add https://github.com/genedelisa/GDLog.git
$ git submodule update --init --recursive
  • Open the new GDLog folder, and drag the GDLog.xcodeproj into the Project Navigator of your application's Xcode project.

It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

  • Select the GDLog.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.
  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
  • In the tab bar at the top of that window, open the "General" panel.
  • Click on the + button under the "Embedded Binaries" section.
  • You will see two different GDLog.xcodeproj folders each with two different versions of the GDLog.framework nested inside a Products folder.

It does not matter which Products folder you choose from.

  • Select the GDLog.framework.

  • And that's it!

The GDLog.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.

Embeded Binaries

  • Download the latest release from https://github.com/genedelisa/GDLog/releases
  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
  • In the tab bar at the top of that window, open the "General" panel.
  • Click on the + button under the "Embedded Binaries" section.
  • Add the downloaded GDLog.framework.
  • And that's it!

Other logging options.

CocoaLumberjack

XCGLogger

The SPM itself has a good logger.

Usage

Apple's Unified Logging

To set the logging level for a subsystem.

$ sudo log config --mode "level:debug" --subsystem com.your_company.your_subsystem_name

For example, from the Terminal (or iterm), set the debug level for your subsystem. Then you can stream the output.


$ sudo log config --mode "level:debug" --subsystem com.rockhoppertech.SlowItDown

$ log stream --predicate 'subsystem == "com.rockhoppertech.SlowItDown"' --info --debug

To check the current logging level.

$ sudo log config --status

Use the system console (and/or Xcode's console) to read the logging messages.

You can filter by your subsystem in the Console app.

Sample Console output:

Console

The message emojis can be redefined per level.

var log = GDLog()
log.debugPrefix = "♫ "
log.debugPostfix = "  ♫"

Here is some sample output.

2017-12-18 15:54:03.611598-0500 SlowItDown[31758:2620634] [general] 😺😺😺 authorized ☞ checkMediaLibraryPermission() 🗄MediaLibraryController.swift➸121 😺😺😺

Other options for creating loggers.

var log2 = GDLog(category: "my category")
log2.debug("logging to my category string")

public enum MyCategories: String {
case mycat
}
var log3 = GDLog(category: MyCategories.mycat.rawValue)
log3.debug("logging to my category enum")

var log4 = GDLog(.controller, category: .general)
log4.debug("logging to controler subsystem using general category")

License

GDLog is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 0
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics