Created
January 2, 2017 10:30
-
-
Save rbresjer/5888c6be584131d9528475dd762c6a14 to your computer and use it in GitHub Desktop.
Simple logger for Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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