Skip to content

Commit c5cb12f

Browse files
committed
Create StytchConsoleLogger
1 parent 4399171 commit c5cb12f

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Sources/StytchCore/StartupClient.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct StartupClient {
4040
_ = try await (auth, bootstrap)
4141

4242
isInitializedPublisher.send(true)
43+
44+
StytchConsoleLogger.log(message: "Stytch SDK initialized for client type: \(clientType)")
4345
}
4446

4547
private static func authenticateSessionIfNeeded(for clientType: ClientType) async {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import Foundation
2+
import os.log
3+
4+
@objc
5+
public final class StytchConsoleLogger: NSObject {
6+
// Create a logger with subsystem and category for filtering in Console
7+
// In Console.app you can filter using:
8+
// subsystem:com.stytch.sdk
9+
// category:console
10+
// You can also combine filters, for example:
11+
// subsystem:com.stytch.sdk level:error
12+
private static let logger = Logger(subsystem: "com.stytch.sdk", category: "console")
13+
}
14+
15+
// These map directly to OSLogType levels and are easy to call.
16+
// Note: error and warning messages always appear in Console by default.
17+
// Info messages do NOT appear unless you enable "Action->Include Info Messages" in Console
18+
// or change log settings via `log config` in Terminal. This is an Apple logging behavior
19+
// designed to reduce noise, not a limitation of this class.
20+
public extension StytchConsoleLogger {
21+
/// Log an informational message
22+
@objc static func log(message: String) {
23+
logger.info("\(message, privacy: .public)")
24+
}
25+
26+
/// Log a warning message
27+
@objc static func warn(message: String) {
28+
logger.warning("\(message, privacy: .public)")
29+
}
30+
31+
/// Log an error message
32+
@objc static func error(message: String) {
33+
logger.error("\(message, privacy: .public)")
34+
}
35+
}
36+
37+
// Use this if you want one entry point with a configurable log level.
38+
// Callers pass in an OSLogType (.debug, .info, .error, etc).
39+
// Example:
40+
// StytchConsoleLogger.log(message: "debugging", type: .debug)
41+
// StytchConsoleLogger.log(message: "problem!", type: .error)
42+
public extension StytchConsoleLogger {
43+
/// Log a message with a custom log level
44+
@objc static func log(message: String, type: OSLogType = .default) {
45+
logger.log(level: type, "\(message, privacy: .public)")
46+
}
47+
}

0 commit comments

Comments
 (0)