1 /* 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * All rights reserved. 4 * 5 * This source code is licensed under the BSD-style license found in the 6 * LICENSE file in the root directory of this source tree. 7 */ 8 9 #import <Foundation/Foundation.h> 10 11 NS_ASSUME_NONNULL_BEGIN 12 13 /** 14 * Defines log levels with specific character codes representing each level. 15 */ 16 typedef NS_ENUM(NSInteger, ExecuTorchLogLevel) { 17 ExecuTorchLogLevelDebug = 'D', 18 ExecuTorchLogLevelInfo = 'I', 19 ExecuTorchLogLevelError = 'E', 20 ExecuTorchLogLevelFatal = 'F', 21 ExecuTorchLogLevelUnknown = '?' 22 } NS_SWIFT_NAME(LogLevel); 23 24 /** 25 * A protocol defining the requirements for a log sink to receive log messages. 26 */ 27 NS_SWIFT_NAME(LogSink) 28 @protocol ExecuTorchLogSink 29 30 /** 31 * Logs a message with the specified additional info. 32 * 33 * @param level The log level of the message. 34 * @param timestamp The timestamp of the log message since ExecuTorch PAL start. 35 * @param filename The name of the file generating the log message. 36 * @param line The line number in the file where the log message was generated. 37 * @param message The log message text. 38 */ 39 - (void)logWithLevel:(ExecuTorchLogLevel)level 40 timestamp:(NSTimeInterval)timestamp 41 filename:(NSString *)filename 42 line:(NSUInteger)line 43 message:(NSString *)message 44 NS_SWIFT_NAME(log(level:timestamp:filename:line:message:)); 45 46 @end 47 48 /** 49 * A singleton class for managing log sinks and dispatching log messages. 50 */ 51 NS_SWIFT_NAME(Log) 52 @interface ExecuTorchLog : NSObject 53 54 /// The shared singleton log instance. 55 @property(class, readonly) ExecuTorchLog *sharedLog; 56 57 /** 58 * Adds a log sink to receive log messages. 59 * 60 * @param sink The log sink to add. 61 */ 62 - (void)addSink:(id<ExecuTorchLogSink>)sink NS_SWIFT_NAME(add(sink:)); 63 64 /** 65 * Removes a previously added log sink. 66 * 67 * @param sink The log sink to remove. 68 */ 69 - (void)removeSink:(id<ExecuTorchLogSink>)sink NS_SWIFT_NAME(remove(sink:)); 70 71 + (instancetype)new NS_UNAVAILABLE; 72 - (instancetype)init NS_UNAVAILABLE; 73 74 @end 75 76 NS_ASSUME_NONNULL_END 77