{"id":17090831,"url":"https://github.com/phimage/slf4swift","last_synced_at":"2025-06-19T07:08:17.063Z","repository":{"id":32849597,"uuid":"36443223","full_name":"phimage/SLF4Swift","owner":"phimage","description":"Simple Logging Facade for Swift serves as a simple facade for logging frameworks allowing the end user to plug in the desired logging framework at deployment time","archived":false,"fork":false,"pushed_at":"2016-10-17T21:08:38.000Z","size":411,"stargazers_count":8,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-19T07:08:07.157Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phimage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-28T14:16:33.000Z","updated_at":"2021-10-02T13:07:19.000Z","dependencies_parsed_at":"2022-07-24T17:32:04.821Z","dependency_job_id":null,"html_url":"https://github.com/phimage/SLF4Swift","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/phimage/SLF4Swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FSLF4Swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FSLF4Swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FSLF4Swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FSLF4Swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phimage","download_url":"https://codeload.github.com/phimage/SLF4Swift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FSLF4Swift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260705875,"owners_count":23049493,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T13:56:51.843Z","updated_at":"2025-06-19T07:08:12.045Z","avatar_url":"https://github.com/phimage.png","language":"Swift","readme":"# SLF4Swift - Simple Loging Facade for Swift\n\n[![Join the chat at https://gitter.im/phimage/SLF4Swift](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/phimage/SLF4Swift?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat\n            )](http://mit-license.org) [![Platform](http://img.shields.io/badge/platform-ios_osx-lightgrey.svg?style=flat\n             )](https://developer.apple.com/resources/) [![Language](http://img.shields.io/badge/language-swift-orange.svg?style=flat\n             )](https://developer.apple.com/swift) [![Issues](https://img.shields.io/github/issues/phimage/SLF4Swift.svg?style=flat\n           )](https://github.com/phimage/Phiole/issues) [![Cocoapod](http://img.shields.io/cocoapods/v/SLF4Swift.svg?style=flat)](http://cocoadocs.org/docsets/SLF4Swift/) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n[\u003cimg align=\"left\" src=\"logo.png\" hspace=\"20\"\u003e](#logo) Simple Log Facade for Swift serves as a simple facade for logging frameworks allowing the end user to plug in the desired logging framework at deployment time\n\n```swift\nlet myLogger = SLF4Swift.getLogger(\"loggerName\")\nmyLogger.info(\"my info message\")\nmyLogger.log(.Error, \"my error message\")\n```\n\nNot already chosen a logging framework? Don't want to be tied to a specific framework and want to switch (or even combine) easily?\nWhy not uing a logging [facade](https://en.wikipedia.org/wiki/Facade_pattern)?\n\nA Simple Logging Facade\n- make your framework or any part of your codes no dependent to a specific logging frameworks ie. reduce the coupling between an application and any particular logging framework\n- allow to log of course with a common interface, avoiding the use of `print()` or `NSLog()` or commented debugging print code\n- allow the end user capture the logs and print using his chosen logging frameworks\n\n# For framework or any part of codes not linked to a logging framework\n## Getting Logger\nGetting the default one\n```swift\nlet myLogger = SLF4Swift.defaultLogger\n```\nGet logger using a key or create if not exist\n```swift\nlet myLogger = SLF4Swift.createLogger(\"loggerKey\")\n```\n*Or just get it - here logger could be nil if not already created*\n```swift\nif let myLogger = SLF4Swift.getLogger(\"loggerKey\") {..}\n```\n\n*A key could be a framework name, a class name, a topic name, ....*\n\nIf you use a key into a framework, create a `public` constant to allow the end user to decide according to this key what to do with your logs (see \u003ca href=\"#custom_factories_and_loggers\"\u003eCustom factories and loggers\u003c/a\u003e)\n\n## Printing like any other log framework\n```swift\nmyLogger.log(.Error, \"my error message\") // basic method\n// and some shortcut\nmyLogger.info(\"my info message\")\nmyLogger.warn(\"my warn message\")\n...\n// if message compute in a long period of time\nif myLogger.isLoggable(.Verbose) {\n\tmyLogger.log(.Verbose, createLongMessageClosure())\n}\nif myLogger.exec(.Verbose) { // or with closure\n\tmyLogger.log(.Verbose, createLongMessageClosure())\n}\n```\nThere is also macro functions for default logger\n```swift\nSLFLogInfo(\"info message\")\nSLFLog(.Verbose, \"verbose message\")\n...\n```\n\nBy declaring `typealias Log = SLFLogLevel` you can also use default logger like this\n```\nLog.Info.message(\"info message\")\nLog.Verbose.message(\"verbose message\")\nLog.Verbose.trace()// print file, function and line\n\n```\n\n# For the end user\n## Installing a logger factory\nBy default is installed a `NullLoggerFactory`, which disable all logs\n```swift\nSLF4Swift.setSharedFactory(NullLoggerFactory.instance)\n```\nTo enable log, set your `LogFactoryType`\n```swift\nSLF4Swift.setSharedFactory(MyCustomLoggerFactory())\n```\n\nor add `DEBUG` to *\"Other Swift Flags\"* into *\"Swift Compiler - Custom Flags\"* section\nthis add by default a `SLFLoggerFactory`, which use by default `print()`\n```swift\nSLF4Swift.setSharedFactory(SLFLoggerFactory.sharedInstance)\n```\n\nSome backend factories are already implemented into [backend folder](/Backend) (see setup for pod)\n```swift\nSLF4Swift.setSharedFactory(CocoaLumberjackMacroLoggerFactory.instance)\n```\n\n## Custom factories and loggers\nYou can your create your own `LogFactoryType` and/or `LoggerType`\n\n- then return a logger according to the logger key used by one framework or any part of code\n\n```swift\nclass MyCustomLoggerFactory: ProxyLoggerFactory {\n\n    func getLogger(name: LoggerKeyType) -\u003e LoggerType? {\n    \tif name == AFrameWorkKey {\n        \treturn NullLogger.instance // deactive log for specifc logger\n        }\n        else if name == AnOtherFrameWorkKey {\n        \tvar logger = super.getLogger(name)\n            logger.level = .DEBUG // set a specific log level\n        \treturn logger\n        }\n        return super.getLogger(name)\n    }\n```\n\n### What you can use\n\nTo create a custom `LogFactoryType` extend\n- `SingleLoggerFactory` if your factory use only one logger\n- `ProxyLoggerFactory` if your want to use an another factory and make some adaptations\n- `SLFLoggerFactory` and override `doCreateLogger`, if you want to store logger into a `Dictionnary` by key\n\nSome basic loggers are already implemented into [implementation folder](/SLF4Swift/Implementation) (log to a file, using nslog, ...)\n\n\n# Contributing #\nDon't hesitate to fork this repository and PR additionnal `LogFactoryType` for your logging framework\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md)\n\n# Setup #\n## Using [cocoapods](http://cocoapods.org/) ##\n\nAdd `pod 'SLF4Swift'` to your `Podfile` and run `pod install`.\n\nAdd `use_frameworks!` to the end of the `Podfile`.\n\n### Backend\n[CocoaLumberjack](https://github.com/CocoaLumberjack/CocoaLumberjack)\n`pod 'SLF4Swift/CocoaLumberjack'`\n\n[XCGLogger](https://github.com/DaveWoodCom/XCGLogger)\n`pod 'SLF4Swift/XCGLogger'`\n\n[SpeedLog](https://github.com/kostiakoval/SpeedLog)\n`pod 'SLF4Swift/SpeedLog'`\n\n[Loggerithm](https://github.com/honghaoz/Loggerithm)\n`pod 'SLF4Swift/Loggerithm'`\n\n### Make your own framework dependent\nIn podspec\n```ruby\ns.dependency 'SLF4Swift'\n```\n\n### For additional logger ie. simple implementation ###\nAdd `pod 'SLF4Swift/Impl'` to your `Podfile`\n\n## Using xcode project ##\n\n1. Drag the.xcodeproj file to your project/workspace or open it to compile it\n2. Add the framework to your project\n\n# Issues\n- Protocol or protocol implentations do not allow to give default value for functions parameters, caller context cannot be passed to log message (`__FILE__`, `__LINE__`, `__FUNCTION__`). If there is a way, I am interested to learn it\n\n# Licence #\nThe MIT License (MIT), see LICENSE file\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphimage%2Fslf4swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphimage%2Fslf4swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphimage%2Fslf4swift/lists"}