Simple logging for simples needs.

Overview

Logger

Test

Simple logging for simples needs.

Getting Started

Declare your dependency in your Package.swift file.

.package(name: "Logger", url: "https://github.com/nativedevbr/swift-log.git", from: "0.1.0"),

and add it to your application target.

.target(name: "BestExampleApp", dependencies: ["Logger"]),

Now, let's learn how to use it.

// Import the logger package.
import Logger

// Create a logger instance, the system is a string that identifies this logging instance.
// It's recommended to use an inverse domain like your bundle identifier.
// This logging implementation is based on destinations, each destination represent a place where
// the log messagens will be sent.
let logger = Logger(system: "br.dev.native.best-example-app", destinations: [.console(), .file(url: URL(...)])

// Then, just call the available methods on the logger instance, there is one method for each
// logging level. [verbose, debug, info, warning and error].
logger.info("Hello World!")

// There's support for adding additional context to a log message.
logger.error("something is not working", context: ["user_id": "deadbeef"])

If you prefer, there's possibility for defining a shared logger instance through Logger.main.

Logger.main = Logger(system: "br.dev.native.best-example-app", destinations: [.console(), .file(url: URL(...)])

If Logger.main is used before being initialized the app will crash.

Destinations

This package provides two destinations out of the box, the console and file.

The console destination sends the log messages to the console and it's debug only, so no logs are sent on release builds.

The file destination writes logs messages to a local file that the user must provide.

Boths destinations accepts a Formatter parameter to customize the formatting logic of the message, there's a default implementation.

Custom destinations

This destination approach makes very easy to add new ones, like this example of a destination that sends the log messages to Crashlytics.

import FirebaseCrashlytics

extension Logger.Destination {
  static let crashlytics = Logger.Destination { msg in
    // You can use the default formatter for generating a string, 
    // or implement your own formatting logic.
    let string = Logger.Formatter.default.format(msg)
    Crashlytics.crashlytics().log(string)
  }
}

// Then to use the new destination, simply init a logger passing the `crashlytics` destination.
Logger.main = Logger(system: "br.dev.native.best-example-app", destinations: [.console(), .crashlytics])

Contributing

Pull requests are welcome.

Please make sure to update tests as appropriate.

License

Apacha 2.0

You might also like...
Willow is a powerful, yet lightweight logging library written in Swift.

Willow Willow is a powerful, yet lightweight logging library written in Swift. Features Requirements Migration Guides Communication Installation Cocoa

Swift Logging Utility for Xcode & Google Docs
Swift Logging Utility for Xcode & Google Docs

QorumLogs Swift Logging Utility in Xcode & Google Docs

A lightweight logging framework for Swift

HeliumLogger Provides a lightweight logging implementation for Swift which logs to standard output. Features Logs output to stdout by default. You can

A lightweight logging framework for Swift

HeliumLogger Provides a lightweight logging implementation for Swift which logs to standard output. Features Logs output to stdout by default. You can

A flexible logging library written in Swift

Puppy Puppy is a flexible logging library written in Swift 🐶 It supports multiple transports(console, file, syslog, and oslog) as loggers. It not onl

In-App iOS Debugging Tool With Enhanced Logging, Networking Info, Crash reporting And More.
In-App iOS Debugging Tool With Enhanced Logging, Networking Info, Crash reporting And More.

The debugger tool for iOS developer. Display logs, network request, device informations, crash logs while using the app. Easy accessible with its bubble head button 🔘 . Easy to integrate in any apps, to handle development or testing apps easier. First version, there is plenty of room for improvement.

An extensible logging framework for Swift
An extensible logging framework for Swift

Log is a powerful logging framework that provides built-in themes and formatters, and a nice API to define your owns. Get the most out of Log by insta

Logging utility for Swift and Objective C
Logging utility for Swift and Objective C

Swell - Swift Logging A logging utility for Swift and Objective C. ##Features Turn on logging during development, turn them off when building for the

A powerful input-agnostic swift logging framework made to speed up development with maximum readability.
A powerful input-agnostic swift logging framework made to speed up development with maximum readability.

The Swift logging framework. Atlantis is an extremely powerful logging framework that I've created for everyday use, including enterprise development

Releases(0.3.0)
Owner
native.dev.br
native.dev.br
Twitter Logging Service is a robust and performant logging framework for iOS clients

Twitter Logging Service Background Twitter created a framework for logging in order to fulfill the following requirements: fast (no blocking the main

Twitter 290 Nov 15, 2022
A logging backend for swift-log that sends logging messages to Logstash (eg. the ELK stack)

LoggingELK LoggingELK is a logging backend library for Apple's swift-log The LoggingELK library provides a logging backend for Apple's apple/swift-log

null 17 Nov 15, 2022
CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant

CleanroomLogger CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant. The API provided by Cleanro

null 1.3k Dec 8, 2022
TraceLog is a highly configurable, flexible, portable, and simple to use debug logging system for Swift and Objective-C applications running on Linux, macOS, iOS, watchOS, and tvOS.

Please star this github repository to stay up to date. TraceLog Introduction TraceLog is a highly configurable, flexible, portable, and simple to use

Tony Stone 52 Oct 28, 2022
Simple, lightweight and flexible debug logging framework written in Swift

AELog Simple, lightweight and flexible debug logging minion written in Swift If you find yourself in upcoming statements, then you probably want to us

Marko Tadić 28 Jul 6, 2022
A fast & simple, yet powerful & flexible logging framework for Mac and iOS

CocoaLumberjack CocoaLumberjack is a fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS. How to get started Fir

null 12.9k Jan 9, 2023
A simple logging package for Swift

OhMyLog OhMyLog is a simple logging package for Swift. It supports the following features: Six logging levels ( ?? , ?? , ?? , ⚠️ , ?? , ?? ) Display

Junhao Wang 1 Jan 10, 2022
A simple, straightforward logging API.

Sequoia A simple, straightforward logging API. Install Add the following to your Package.swift file: import PackageDescription let package = Package(

Jordan Baird 0 Dec 18, 2022
Convenient & secure logging during development & release in Swift 3, 4 & 5

Colorful, flexible, lightweight logging for Swift 3, Swift 4 & Swift 5. Great for development & release with support for Console, File & cloud platfor

SwiftyBeaver 5.6k Jan 4, 2023
Class for logging excessive blocking on the main thread

Watchdog Class for logging excessive blocking on the main thread. It watches the main thread and checks if it doesn’t get blocked for more than define

Wojtek Lukaszuk 1.8k Dec 6, 2022