Swiftpack.co - forkercat/OhMyLog as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by forkercat.
forkercat/OhMyLog v1.1.0
Simple Logging Package in Swift 📋
⭐️ 1
🕓 33 weeks ago
.package(url: "https://github.com/forkercat/OhMyLog.git", from: "v1.1.0")

OhMyLog: Simple Logging Package in Swift 📋

macOS Linux Windows license

platform-compatibility swift-version-compatibility

OhMyLog is a simple logging package for Swift. It supports the following features:

  • Six logging levels: TRACE 🟤, DEBUG 🟢, INFO ⚪️, WARN 🟡, ERROR 🔴, FATAL 🚨
  • Display log context including filename and line number
  • Show time
  • Output string or any object directly similar to print()
  • Toogle display of level icons and context information

🔧 Install

You package file would be like:

let package = Package(
    name: "YourPackageName",
    dependencies: [
        .package(url: "https://github.com/forkercat/OhMyLog.git", .branch("main")),
    targets: [
        // For Swift 5.5, use .executableTarget
            name: "YourPackageName",
            dependencies: [
                .product(name: "OhMyLog", package: "OhMyLog")

😆 Usage

Option 1️⃣: Use Logger object

import OhMyLog

var logger = Logger(name: "Example-1", level: .info)
logger.logLevel = .trace
logger.showLevelIcon = true

let list = ["Oh", "My", "Log"]

logger.trace("Hello, World! \(list)")
logger.debug("Hello, World! \(list)")
logger.info("Hello, World! \(list)")
logger.warn("Hello, World! \(list)")
logger.error("Hello, World! \(list)")
logger.fatal("Hello, World! \(list)")

// Output
🟤 [06:52:31.672] TRACE Example-1: Hello, World! ["Oh", "My", "Log"]
🟢 [06:52:31.672] DEBUG Example-1: Hello, World! ["Oh", "My", "Log"]
⚪️ [06:52:31.673] INFO Example-1: Hello, World! ["Oh", "My", "Log"]
🟡 [06:52:31.673] WARN Example-1: Hello, World! ["Oh", "My", "Log"]
🔴 [06:52:31.673] ERROR Example-1: Hello, World! ["Oh", "My", "Log"]
🚨 [06:52:31.673] FATAL Example-1: Hello, World! ["Oh", "My", "Log"]

Option 2️⃣: Use Log namespace

import OhMyLog

Log.registerLogger(name: "Example-2", level: .info)
Log.setLevel(level: .info)
Log.info("Hello, World! \(list)")
Log.logLevel = .trace
Log.showLevelIcon(enabled: false)

let list = ["Oh", "My", "Log"]

// Output
[INFO] [06:52:31.673] Example-2 main.swift:26 - Hello, World! ["Oh", "My", "Log"]
[WARN] [06:52:31.674] Example-2 main.swift:26 - Hello, World! ["Oh", "My", "Log"]

Option 3️⃣: Without import

Create a swift source file in your project with two lines.

import OhMyLog

typealias Log = OhMyLog.Log

Now you are able to log without import OhMyLog.

Log.registerLogger(name: "Example-3", level: .info)
Log.setLevel(level: .info)

let six = 666


// Output
🟤 [06:52:31.673] TRACE Example-3: 30
⚪️ [06:52:31.673] INFO Example-3: 666

🙏 Reference


Stars: 1
Last commit: 31 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

33 weeks ago
  • Add time
  • Minor improvements

Full Changelog: https://github.com/forkercat/OhMyLog/compare/v1.0.0...v1.1.0

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