Simple yet advanced swift logger

What's New

Release 1.1.1


Quick scheme and swift update


Swift 5.2 License Continuous Integration Codebeat

SLLog is a simple yet elegant swift logger. Allows you to log content to file, console or your custom target.

1990-02-19T22:45:36.250Z [VERBOSE] MyFile.swift:19 - 123
1991-03-20T20:33:44.777Z [INFO] MyFile.swift:20 - ABC
1992-04-21T09:53:51.021Z [DEBUG] MyFile.swift:21 - @$#!^%
1993-05-22T11:05:02.000Z [WARNING] MyFile.swift:22 - 2017-10-04 22:45:36 +0000
1994-06-23T15:13:00.146Z [ERROR] MyFile.swift:23 - [0.10000000000000001, 1, "A", 2017-10-04 09:55:36 +0000]

Terminal Console

🔧 Installation

Add the following dependency to your Package.swift file:

.package(url: "", from: "1.1.0"),

💊 How To Start

1 Import

On top of your file import:

import SLLog

2 Usage

Log any information you need with Log class


Any object.


3 Initialize

Setup SLLoger

SLLog.addHandler(try! SLLogFile("path/to/directory"))

Or console handler


or both

SLLog.addHandler(SLLogConsole(), try! SLLogFile(path))

You can create your custom log handler. Simply correspond to LogHandler protocol.

public class MyHandler: LogHandler {
    open func handle(message: Any, level: SLLog.LogType, file: String, line: UInt) {
        //Do your stuff with log.

then add it to SLLog


4 Providers

SLLog can have custom providers. To add your own provider

struct MySLLogProvider: LogProvider {}

can you can use LogProvider build in method send. To send your log via SLLog.

5 SLLogConsole

Default console log:

isDebug: Bool = true,
isTerminal: Bool = {
        #if Xcode
        return false
        return true
minProductionLogType: UInt = 3
logFormat: String = ":d :t :f::l :m",
dateFormat: String? = nil,
logColors: [SLLog.LogType:LogColor]? = nil

Override argument passing it in initializer to variate ConsoleLog SLLogConsole(isDebug: true, isTerminal: false) or SLLogConsole(isTerminal: false) and so on. Use isTerminal property to choose between terminal or console settings. SLLogConsole(isTerminal: false)

To fully configure SLLog pas Configuration object during initialisation. public init(_ config: Configuration = Configuration())

By default, logs are set for a terminal. log format ":d :t :f::l :m" where

`:d` is replaced in string to display date
`:t` is replaced by log type
`:f` is replaced by file name
`:l` is replaced by line number
`:m` is replaced by message object

Default date format used by logger is as follow "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

To get rid of default log colors pass empty dictionary in logColors or dictionary with your own definitions. For more information about terminal color take a look:


LogColor is defined as follow init(_ terminal: String, _ console: String) For XCode console emoticons are used as collor.

SLLog.LogType.verbose:LogColor(TerminalColor.lightGray, "☑️"),, "Ⓜ️"),
SLLog.LogType.debug:LogColor(TerminalColor.lightGreen, ""),
SLLog.LogType.warning:LogColor(TerminalColor.lightYellow, "⚠️"),
SLLog.LogType.error:LogColor(TerminalColor.lightRed, "⛔️"),

Use TerminalColor to fast access predefined colors values

5 SLLogFile

SLLogFile save logs to files which are created on daily basis. File names are as follows: "yyyy-MM-dd". Created under :yuorPath/sllogs with extension .log Default maxFilesCount is set to 3 wich means logger stores 3 files at a time. 1 file = 1 day logs

⭐ Contributing

Be welcome to contribute to this project! :)

❓ Questions

You can create an issue on GitHub.

📝 License

This project was released under the MIT license.


  • Swift Tools 5.2.0
View More Packages from this Author


  • None
Last updated: Fri Jun 28 2024 23:55:56 GMT-0900 (Hawaii-Aleutian Daylight Time)