mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-05 18:58:51 +00:00
Make LogHandler customizable
This commit is contained in:
@@ -3,18 +3,22 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "HockeySDKEnums.h"
|
||||
|
||||
#define BITHockeyLog(_level, _message, ...) [BITHockeyLogger logLevel:_level function:__PRETTY_FUNCTION__ line:__LINE__ message:_message, ##__VA_ARGS__]
|
||||
#define BITHockeyLog(_level, _message, ...) [BITHockeyLogger logLevel:_level file:__FILE__ function:__PRETTY_FUNCTION__ line:__LINE__ message:_message, ##__VA_ARGS__]
|
||||
|
||||
#define BITHockeyLogError(format, ...) BITHockeyLog(BITLogLevelError, format, ##__VA_ARGS__)
|
||||
#define BITHockeyLogWarning(format, ...) BITHockeyLog(BITLogLevelWarning, format, ##__VA_ARGS__)
|
||||
#define BITHockeyLogDebug(format, ...) BITHockeyLog(BITLogLevelDebug, format, ##__VA_ARGS__)
|
||||
#define BITHockeyLogVerbose(format, ...) BITHockeyLog(BITLogLevelVerbose, format, ##__VA_ARGS__)
|
||||
|
||||
typedef void (^BITLogHandler)(BITLogLevel, const char *, const char *, uint, NSString *);
|
||||
|
||||
@interface BITHockeyLogger : NSObject
|
||||
|
||||
+ (BITLogLevel)currentLogLevel;
|
||||
+ (void)setCurrentLogLevel:(BITLogLevel)currentLogLevel;
|
||||
|
||||
+ (void)logLevel:(BITLogLevel)loglevel function:(const char *)function line:(int)line message:(NSString *)message, ...;
|
||||
+ (void)setLogHandler:(BITLogHandler)logHandler;
|
||||
|
||||
+ (void)logLevel:(BITLogLevel)loglevel file:(const char *)file function:(const char *)function line:(uint)line message:(NSString *)message, ...;
|
||||
|
||||
@end
|
||||
|
||||
@@ -13,14 +13,24 @@ static BITLogLevel _currentLogLevel = BITLogLevelWarning;
|
||||
_currentLogLevel = currentLogLevel;
|
||||
}
|
||||
|
||||
+ (void)logLevel:(BITLogLevel)logLevel function:(const char *)function line:(int)line message:(NSString *)message, ... {
|
||||
va_list args;
|
||||
static BITLogHandler currentLogHandler = ^(BITLogLevel logLevel, const char *file, const char *function, uint line, NSString *message) {
|
||||
if (message) {
|
||||
va_start(args, message);
|
||||
if (self.currentLogLevel < logLevel) {
|
||||
if (_currentLogLevel < logLevel) {
|
||||
return;
|
||||
}
|
||||
NSLog((@"[HockeySDK] %s/%d %@"), function, line, [[NSString alloc] initWithFormat:message arguments:args]);
|
||||
NSLog((@"[HockeySDK] %s/%d %@"), function, line, message);
|
||||
}
|
||||
};
|
||||
|
||||
+ (void)setLogHandler:(BITLogHandler)logHandler {
|
||||
currentLogHandler = logHandler;
|
||||
}
|
||||
|
||||
+ (void)logLevel:(BITLogLevel)loglevel file:(const char *)file function:(const char *)function line:(uint)line message:(NSString *)message, ... {
|
||||
if (currentLogHandler) {
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
currentLogHandler(loglevel, file, function, line, [[NSString alloc] initWithFormat:message arguments:args]);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user