Skip to content

Commit b9b4a09

Browse files
committed
added option for production / release logging
1 parent d9a1b5d commit b9b4a09

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ There is also a shortcut print statement for an error object. This will print th
7474

7575
Update: From now on printing .error will also give you a stacktrace.
7676

77+
Update 04-04-2019 : You can now also set the minimumLogLevel to productionLogAll. This will make sure you can also see the logging in the console (menu 'Window', 'Devices and Simulators', 'Open Console') In most cases you should only use this if you want to see logging for an app that you distributed using Testflight.
78+
7779
## Enum
7880

7981
You can install this by adding the following line to your Podfile:

Source/Print/Print.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
//
77

88
import Foundation
9+
import os.log
910

1011
/**
1112
Extending the Stuff object with print functionality
1213
*/
1314
public extension Stuff {
14-
15+
1516
/**
1617
Enumeration of the log levels
1718
*/
1819
public enum logLevel: Int {
20+
// Make sure all log events goes to the device log
21+
case productionLogAll = 0
1922
// Informational loging, lowest level
2023
case info = 1
2124
// Debug loging, default level
@@ -28,7 +31,7 @@ public extension Stuff {
2831
case fatal = 5
2932
// Set the minimumLogLevel to .none to stop everything from loging
3033
case none = 6
31-
34+
3235
/**
3336
Get the emoticon for the log level.
3437
*/
@@ -44,12 +47,12 @@ public extension Stuff {
4447
return "🚫"
4548
case .fatal:
4649
return "🆘"
47-
case .none:
50+
case .none, .productionLogAll:
4851
return ""
4952
}
5053
}
5154
}
52-
55+
5356
/**
5457
Set the minimum log level. By default set to .info which is the minimum. Everything will be loged.
5558
*/
@@ -67,7 +70,17 @@ public extension Stuff {
6770
let file = URL(string: filename)?.lastPathComponent ?? ""
6871
let traceOutput: String = trace.map { "\t\t\($0)" }.reduce("\n") { "\($0)\n\($1)" }
6972
let output: String = object is Error ? "\((object as! Error).localizedDescription)\(traceOutput)" : "\(object)"
70-
Swift.print("\n\(level.description()) .\(level)\(dateFormatter.string(from: Foundation.Date())) 📱 \(process.processName) [\(process.processIdentifier):\(threadId)] 📂 \(file)(\(line)) ⚙️ \(funcname) ➡️\r\t\(output)")
73+
var logText = "\n\(level.description()) .\(level)\(dateFormatter.string(from: Foundation.Date())) 📱 \(process.processName) [\(process.processIdentifier):\(threadId)] 📂 \(file)(\(line)) ⚙️ \(funcname) ➡️\r\t\(output)"
74+
if Stuff.minimumLogLevel == .productionLogAll {
75+
if #available(iOSApplicationExtension 10.0, *) {
76+
let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Stuff")
77+
os_log("%{public}@", log: log, logText)
78+
} else {
79+
NSLog("#Stuff# /(logText)")
80+
}
81+
} else {
82+
Swift.print(logText)
83+
}
7184
}
7285
}
7386
}

Stuff.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Stuff"
3-
s.version = "1.0.0"
3+
s.version = "1.1.0"
44
s.summary = "Too small for a library, too important to just forget"
55

66
s.description = <<-EOS

0 commit comments

Comments
 (0)