Experimental SSL support
This commit is contained in:
34
kordophone/Utilities/MBIMLogging.h
Normal file
34
kordophone/Utilities/MBIMLogging.h
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// MBIMLogging.h
|
||||
// kordophoned
|
||||
//
|
||||
// Created by James Magahern on 1/22/19.
|
||||
// Copyright © 2019 James Magahern. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef enum {
|
||||
ML_INFO,
|
||||
ML_NOTIFY,
|
||||
ML_ERROR,
|
||||
ML_FATAL
|
||||
} MBIMLogLevel;
|
||||
|
||||
extern void __MBIMLogCommon(MBIMLogLevel level, NSString *format, ...);
|
||||
|
||||
#define MBIMLogInfo(format, ...) \
|
||||
__MBIMLogCommon(ML_INFO, format, ##__VA_ARGS__)
|
||||
|
||||
#define MBIMLogNotify(format, ...) \
|
||||
__MBIMLogCommon(ML_NOTIFY, format, ##__VA_ARGS__)
|
||||
|
||||
#define MBIMLogError(format, ...) \
|
||||
__MBIMLogCommon(ML_ERROR, format, ##__VA_ARGS__)
|
||||
|
||||
#define MBIMLogFatal(format, ...) \
|
||||
__MBIMLogCommon(ML_FATAL, format, ##__VA_ARGS__)
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
44
kordophone/Utilities/MBIMLogging.m
Normal file
44
kordophone/Utilities/MBIMLogging.m
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// MBIMLogging.m
|
||||
// kordophoned
|
||||
//
|
||||
// Created by James Magahern on 1/22/19.
|
||||
// Copyright © 2019 James Magahern. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MBIMLogging.h"
|
||||
|
||||
#define ESC(inner) "\033[" inner "m"
|
||||
#define CLR ESC("0")
|
||||
#define BLD "1;"
|
||||
#define RED "31;"
|
||||
|
||||
extern void __MBIMLogCommon(MBIMLogLevel level, NSString *format, ...)
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
static NSDateFormatter *dateFormatter = nil;
|
||||
dispatch_once(&onceToken, ^{
|
||||
dateFormatter = [[NSDateFormatter alloc] init];
|
||||
dateFormatter.dateFormat = @"Y-MM-d HH:mm:ss";
|
||||
});
|
||||
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
NSString *message = [[NSString alloc] initWithFormat:format arguments:args];
|
||||
va_end(args);
|
||||
|
||||
const char *c_fmt = "%s";
|
||||
if (level == ML_NOTIFY) {
|
||||
// BOLD
|
||||
c_fmt = ESC(BLD) "%s";
|
||||
} else if (level == ML_ERROR) {
|
||||
c_fmt = ESC(RED) "%s";
|
||||
} else if (level == ML_FATAL) {
|
||||
c_fmt = ESC(BLD RED) "%s";
|
||||
}
|
||||
|
||||
NSString *dateStr = [dateFormatter stringFromDate:[NSDate date]];
|
||||
fprintf(stdout, "%s: ", [dateStr UTF8String]);
|
||||
fprintf(stdout, c_fmt, [message UTF8String]);
|
||||
fprintf(stdout, CLR "\n");
|
||||
}
|
||||
Reference in New Issue
Block a user