All Projects → sushichop → Puppy

sushichop / Puppy

Licence: MIT license
A flexible logging library written in Swift

Programming Languages

swift
15916 projects
shell
77523 projects
CMake
9771 projects
Makefile
30231 projects
ruby
36898 projects - #4 most used programming language
Starlark
911 projects

Projects that are alternatives of or similar to Puppy

Perfect-URLRouting
Perfect Example Module: URL Routing
Stars: ✭ 20 (-68.75%)
Mutual labels:  server-side-swift
gotomation
No description or website provided.
Stars: ✭ 18 (-71.87%)
Mutual labels:  darwin
bugsnag
Report errors with Bugsnag 🐛
Stars: ✭ 37 (-42.19%)
Mutual labels:  server-side-swift
auth
👤 Authentication and Authorization framework for Fluent.
Stars: ✭ 51 (-20.31%)
Mutual labels:  server-side-swift
gsmartcontrol
GSmartControl - Hard disk drive and SSD health inspection tool
Stars: ✭ 183 (+185.94%)
Mutual labels:  darwin
emacs
Nightly custom Emacs builds for macOS Nix environments
Stars: ✭ 25 (-60.94%)
Mutual labels:  darwin
Perfect-XML
XML support for Perfect.
Stars: ✭ 16 (-75%)
Mutual labels:  server-side-swift
Stevenson
Stevenson is a Vapor framework designed to build integrations between Slack apps, GitHub, JIRA and CI services (CircleCI).
Stars: ✭ 57 (-10.94%)
Mutual labels:  server-side-swift
Postgres-StORM
PostgreSQL StORM Module
Stars: ✭ 24 (-62.5%)
Mutual labels:  server-side-swift
flash
Flash messages between views ⚡️
Stars: ✭ 34 (-46.87%)
Mutual labels:  server-side-swift
apfs
Package apfs implements an Apple File System(apfs) bindings for Go
Stars: ✭ 30 (-53.12%)
Mutual labels:  darwin
gatekeeper
Rate limiting middleware for Vapor 👮
Stars: ✭ 54 (-15.62%)
Mutual labels:  server-side-swift
pointfreeco-server
Point-Free server code.
Stars: ✭ 39 (-39.06%)
Mutual labels:  server-side-swift
swiftbox
SwiftBox is a package that helps building Swift/Vapor microservices.
Stars: ✭ 18 (-71.87%)
Mutual labels:  server-side-swift
Perfect-HTTPServer
HTTP server for Perfect.
Stars: ✭ 104 (+62.5%)
Mutual labels:  server-side-swift
libproc-rs
A rust library for getting information about running processes for Mac and Linux
Stars: ✭ 33 (-48.44%)
Mutual labels:  darwin
osxbom
A reimplementation of lsbom
Stars: ✭ 24 (-62.5%)
Mutual labels:  darwin
awesome-server-side-swift
A community curated list of resources about Server Side Swift
Stars: ✭ 82 (+28.13%)
Mutual labels:  server-side-swift
Perfect-Zip
Perfect Zip compression utility.
Stars: ✭ 20 (-68.75%)
Mutual labels:  server-side-swift
Perfect-Thread
Core threading library for Perfect Server Side Swift. Includes support for serial and concurrent thread queues, locks, read/write locks and events.
Stars: ✭ 17 (-73.44%)
Mutual labels:  server-side-swift

Puppy

Swift5.4+ release CocoaPods CI codecov license

platforms SwiftPM|CMake|Bazel|Carthage

Puppy is a flexible logging library written in Swift 🐶

It supports multiple transports(console, file, syslog, and oslog) as loggers. It not only works alone, but also as a backend for apple/swift-log.

Furthermore, it has file log rotation feature and you can also customize the log format as you like. And it supports cross-platform(Darwin, Linux, and Windows).

Features

  • Written in Swift.
  • Supports cross-platform(Darwin, Linux, and Windows).
  • Supports console, file, syslog, and oslog as loggers.
  • Supports automatic log rotation about file logger.
  • Also Works as a backend for apple/swift-log.

Examples

Basic Usage

Logging to mutliple transports(e.g. console and file). It is recommended that the first argument of each logger be a unique reverse-order FQDN since it is also used internally for a DispatchQueue's label.

import Puppy

let console = ConsoleLogger("com.example.yourapp.console")
let fileURL = URL(fileURLWithPath: "./foo.log").absoluteURL
let file = FileLogger("com.example.yourapp.file",
                      fileURL: fileURL,
                      filePermission: "600")  // Default permission is "640". 

let log = Puppy()
// Set the logging level.
log.add(console, withLevel: .warning)
log.add(file, withLevel: .warning)

log.debug("DEBUG message")  // Will NOT be logged.
log.error("ERROR message")  // Will be logged.

Use with apple/swift-log

Logging to mutliple transports(e.g. console and syslog) as a backend for apple/swift-log.

import Puppy
import Logging

let console = ConsoleLogger("com.example.yourapp.console")
let syslog = SystemLogger("com.example.yourapp.syslog")

let puppy = Puppy.default
puppy.add(console)
puppy.add(syslog)

LoggingSystem.bootstrap {
    var handler = PuppyLogHandler(label: $0, puppy: puppy)
    // Set the logging level.
    handler.logLevel = .trace
    return handler
}

let log = Logger(label: "com.example.yourapp.swiftlog")

log.trace("TRACE message")  // Will be logged.
log.debug("DEBUG message")  // Will be logged.

Use file log rotation

Logging to file and use log rotation feature.

import Puppy

class ViewController: UIViewController {
    let delegate = SampleFileRotationDelegate()
    override func viewDidLoad() {
        super.viewDidLoad()
        let fileRotation = try! FileRotationLogger("com.example.yourapp.filerotation",
                                                   fileURL: "./logs/foo.log")
        fileRotation.suffixExtension = .date_uuid   // Default option is `.numbering`.
        fileRotation.maxFileSize = 10 * 1024 * 1024
        fileRotation.maxArchivedFilesCount = 5
        fileRotation.delegate = delegate
        let log = Puppy()
        log.add(fileRotation)
        log.info("INFO message")
        log.warning("WARNING message")
    }
}

class SampleFileRotationDelegate: FileRotationLoggerDeletate {
    func fileRotationLogger(_ fileRotationLogger: FileRotationLogger,
                            didArchiveFileURL: URL, toFileURL: URL) {
        print("didArchiveFileURL: \(didArchiveFileURL), toFileURL: \(toFileURL)")
    }
    func fileRotationLogger(_ fileRotationLogger: FileRotationLogger,
                            didRemoveArchivedFileURL: URL) {
        print("didRemoveArchivedFileURL: \(didRemoveArchivedFileURL)")
    }
}

Customize the log format

Customize the log format using Formattable protocol. Logging to oslog for example.

import Puppy

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let oslog = OSLogger("com.yourapp.oslog")
        oslog.format = LogFormatter()
        let log = Puppy()
        log.add(oslog)
        log.info("INFO message")
        log.warning("WARNING message")
    }
}

class LogFormatter: LogFormattable {
    func formatMessage(_ level: LogLevel, message: String, tag: String, function: String,
                       file: String, line: UInt, swiftLogInfo: [String : String],
                       label: String, date: Date, threadID: UInt64) -> String {
        let date = dateFormatter(date)
        let file = shortFileName(file)
        return "\(date) \(threadID) [\(level.emoji) \(level)] \(file)#L.\(line) \(function) \(message)"
    }
}

Create a custom logger

You can create your own custom logger. All you have to do is inherit BaseLogger class and override log(_:string:) method.

import Puppy

class CustomLogger: BaseLogger {
    override func log(_ level: LogLevel, string: String) {
        // Implements the logging feature here.
    }
}

License

Puppy is available under the MIT license. See the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].