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.
APACHE-2.0 License
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.
Writers
and filters that work for your particular use case. Write your own custom Writer
s to plug into TraceLog for customized use-cases.log
statements to your app and get useful output on any platform.OutputStreamWriter
s)
OutputStreamWriter
.OutputStreamWriter
.Using TraceLog is incredibly simple out of the box. Although TraceLog is highly configurable, to get started all you have to do is add the pod to your project, import TraceLog to the files that require logging and start adding log statements where you need them. TraceLog initializes itself and does everything else for you.
In your Podfile
add TraceLog.
target 'MyApp'
pod "TraceLog", '~>5.0'
If you have mixed Swift and Objective-C code, you must specify the subspec to enable Objective-C as follows:
target 'MyApp'
pod "TraceLog", '~>5.0'
pod "TraceLog/ObjC", '~>5.0'
Import TraceLog into you files and start logging.
import TraceLog
struct MyStruct {
func doSomething() {
logInfo { "A simple TraceLog Test message" }
}
}
TraceLog has the following primary logging functions to log various levels of information. The output of these can be controlled via the environment variables at runtime or programmatically at application startup via the TraceLog.configure()
func.
logError (tag: String?, message: @escaping () -> String)
logWarning(tag: String?, message: @escaping () -> String)
logInfo (tag: String?, message: @escaping () -> String)
logTrace (tag: String?, level: UInt, message: @escaping () -> String)
logTrace (level: UInt, @escaping message: () -> String)
Note: hidden parameters and defaults were omitted for simplicity.
Although not strictly require, calling the TraceLog.configure()
command at startup will allow TraceLog to read the environment for configuration information.
Simply call configure with no parameters as early as possible in your startup code (preferably before ay log statements get called.)
TraceLog.configure()
For a complete documentation set including user guides, a 100% documented API reference and many more examples, please see https://tonystone.io/tracelog.
The Swift implementation was designed to take advantage of swift compiler optimizations and will incur no overhead when compiled with optimization on (-O
) and TRACELOG_DISABLED
is defined.
The Objective-C implementation was designed to take advantage of the preprocessor and when compiled with TRACELOG_DISABLED
defined, will incur no overhead in the application.
For XCode TRACELOG_DISABLED
can be set in the project target. For Swift Package Manager pass a swiftc directive to swift build
as in the following example.
swift build -Xswiftc -DTRACELOG_DISABLED
Build Environment
Platform | Version | Swift | Swift Build | Xcode |
---|---|---|---|---|
Linux | Ubuntu 14.04, 16.04, 16.10 | 5.0 | ✔ | ✘ |
OSX | 10.13 | 5.0 | ✔ | Xcode 10.x |
Minimum Runtime Version
iOS | OS X | tvOS | watchOS | Linux |
---|---|---|---|---|
9.0 | 10.13 | 9.0 | 2.0 | Ubuntu 14.04, 16.04, 16.10 |
Note:
To build and run on Linux we have a a pre-configured Vagrant file located at https://github.com/tonystone/vagrant-swift
See the README for instructions.
TraceLog now supports dependency management via Swift Package Manager on All Apple OS variants as well as Linux.
Please see Swift Package Manager for further information.
TraceLog is available through CocoaPods. See the Quick Start Guide for installing through CocoaPods.
See the "Using CocoaPods" guide for more information on CocoaPods itself.
Tony Stone (https://github.com/tonystone)
TraceLog is released under the Apache License, Version 2.0