Created
May 10, 2018 20:51
-
-
Save shijianjian/3786c051da28e5d1bd1d5014d589b897 to your computer and use it in GitHub Desktop.
Enable wireless logging on structure.io sensor.
This file contains hidden or 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
// Enable logging as: | |
// if (WirelessLogging.DEBUG_MODE){ | |
// WirelessLogging.shared.initRemoteLogging() | |
// } | |
// Logging as: | |
// WirelessLogging.log(message: "Success", log: "sensor", type: .debug) | |
import Foundation | |
import os.log | |
class WirelessLogging { | |
private let REMOTE_DEBUG_PORT: Int32 = 4999 | |
private let remoteHost = YOUR_HOST_IP_ADDRESS | |
static let DEBUG_MODE = true | |
// MARK: Shared Instance | |
static let shared: WirelessLogging = WirelessLogging() | |
// MARK: Shared Logger | |
static func log(message: String, log: String? = "root", type: OSLogType?) { | |
if (!self.DEBUG_MODE) { | |
NSLog("[\(log ?? "root")] \(message)") | |
} | |
} | |
func initRemoteLogging() { | |
// STWirelessLog is very helpful for debugging while your Structure Sensor is plugged in. | |
// See SDK documentation for how to start a listener on your computer. | |
var error: NSError? = nil | |
// IP address of your Mac | |
// Inspect with `nc -lk <port>` | |
STWirelessLog.broadcastLogsToWirelessConsole(atAddress: remoteHost, usingPort: REMOTE_DEBUG_PORT, error: &error) | |
NSLog("Wireless Logging started ...") | |
if error != nil { | |
let errmsg = error!.localizedDescription | |
NSLog("Oh no! Can't start wireless log: " + errmsg) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment