forked from DanTheMan827/ios-app-signer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.swift
32 lines (28 loc) · 1.21 KB
/
Log.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// Log.swift
// iOS App Signer
//
// Created by Daniel Radtke on 11/14/15.
// Copyright © 2015 Daniel Radtke. All rights reserved.
//
import Foundation
class Log {
static let mainBundle = Bundle.main
static let bundleID = mainBundle.bundleIdentifier
static let bundleName = mainBundle.infoDictionary!["CFBundleName"]
static let bundleVersion = mainBundle.infoDictionary!["CFBundleShortVersionString"]
static let tempDirectory = NSTemporaryDirectory()
static var logName = Log.tempDirectory.stringByAppendingPathComponent("\(Log.bundleID!)-\(Date().timeIntervalSince1970).log")
static func write(_ value:String) {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
if let outputStream = OutputStream(toFileAtPath: logName, append: true) {
outputStream.open()
let text = "\(formatter.string(from: Date())) \(value)\n"
let data = text.data(using: String.Encoding.utf8, allowLossyConversion: false)!
outputStream.write((data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count), maxLength: data.count)
outputStream.close()
}
NSLog(value)
}
}