Skip to content

Instantly share code, notes, and snippets.

@rbresjer
Created January 2, 2017 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbresjer/5888c6be584131d9528475dd762c6a14 to your computer and use it in GitHub Desktop.
Save rbresjer/5888c6be584131d9528475dd762c6a14 to your computer and use it in GitHub Desktop.
Simple logger for Swift
//
// LogManager.swift
//
// Created by Rutger Bresjer on 30/11/2016.
// Copyright © 2016 Woost. All rights reserved.
//
import Foundation
import RxSwift
func log(_ message: String, file: String = #file, line: Int = #line, function: String = #function) {
let fileName = file.components(separatedBy: "/").last ?? file
let formattedMessage = "[\(fileName):\(line):\(function)] \(message)"
#if DEBUG
print(formattedMessage)
#endif
LogManager.shared.log(formattedMessage)
}
class LogManager {
static let shared = LogManager()
private init() {}
public let messages = Variable("")
fileprivate func log(_ message: String) {
messages.value.append(message + "\n")
}
func clearLog() {
messages.value = ""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment