-
-
Save LambergaR/2a6b10eb197c106c115fcb41ef399b3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Generated by the J2ObjC translator. DO NOT EDIT! | |
// source: /java/util/logging/IOSLogHandler.java | |
// | |
#include "J2ObjC_source.h" | |
#include "java/io/PrintWriter.h" | |
#include "java/io/StringWriter.h" | |
#include "java/lang/StringBuilder.h" | |
#include "java/util/logging/Formatter.h" | |
#include "java/util/logging/Handler.h" | |
#include "java/util/logging/IOSLogHandler.h" | |
#include "java/util/logging/Level.h" | |
#include "java/util/logging/LogRecord.h" | |
#import "NSException+JavaThrowable.h" | |
#import <asl.h> | |
// Simple value holder, so aslclient is closed when thread dictionary is deallocated. | |
@interface ASLClientHolder : NSObject { | |
@public | |
aslclient _client; | |
} | |
@end | |
@implementation ASLClientHolder | |
- (instancetype)initWithClient:(aslclient)client { | |
self = [super init]; | |
if (self) { | |
_client = client; | |
} | |
return self; | |
} | |
- (void)dealloc { | |
asl_close(_client); | |
#if !__has_feature(objc_arc) | |
[super dealloc]; | |
#endif | |
} | |
@end | |
@interface JavaUtilLoggingIOSLogHandler () | |
- (void)logWithNSString:(NSString *)logMessage | |
withInt:(jint)aslLevel; | |
@end | |
inline NSString *JavaUtilLoggingIOSLogHandler_get_ASLCLIENT(); | |
static NSString *JavaUtilLoggingIOSLogHandler_ASLCLIENT = @"IOSLogHandler-aslclient"; | |
J2OBJC_STATIC_FIELD_OBJ_FINAL(JavaUtilLoggingIOSLogHandler, ASLCLIENT, NSString *) | |
__attribute__((unused)) static void JavaUtilLoggingIOSLogHandler_logWithNSString_withInt_(JavaUtilLoggingIOSLogHandler *self, NSString *logMessage, jint aslLevel); | |
NSString *JavaUtilLoggingIOSLogHandler_IOS_LOG_MANAGER_DEFAULTS = @".level=INFO\nhandlers=java.util.logging.IOSLogHandler\n"; | |
@implementation JavaUtilLoggingIOSLogHandler | |
J2OBJC_IGNORE_DESIGNATED_BEGIN | |
- (instancetype)init { | |
JavaUtilLoggingIOSLogHandler_init(self); | |
return self; | |
} | |
J2OBJC_IGNORE_DESIGNATED_END | |
- (void)close { | |
} | |
- (void)flush { | |
} | |
- (void)publishWithJavaUtilLoggingLogRecord:(JavaUtilLoggingLogRecord *)record { | |
if (![self isLoggableWithJavaUtilLoggingLogRecord:record]) { | |
return; | |
} | |
JavaLangStringBuilder *sb = create_JavaLangStringBuilder_initWithNSString_([((JavaUtilLoggingFormatter *) nil_chk([self getFormatter])) formatWithJavaUtilLoggingLogRecord:record]); | |
jint aslLevel; | |
switch ([((JavaUtilLoggingLevel *) nil_chk([((JavaUtilLoggingLogRecord *) nil_chk(record)) getLevel])) intValue]) { | |
case 1000: | |
aslLevel = 3; | |
break; | |
case 900: | |
aslLevel = 4; | |
break; | |
case 800: | |
case 700: | |
aslLevel = 5; | |
break; | |
default: | |
aslLevel = 6; | |
} | |
if ([record getThrown] != nil) { | |
[sb appendWithChar:0x000a]; | |
JavaIoStringWriter *stringWriter = create_JavaIoStringWriter_init(); | |
[((NSException *) nil_chk([record getThrown])) printStackTraceWithJavaIoPrintWriter:create_JavaIoPrintWriter_initWithJavaIoWriter_(stringWriter)]; | |
[sb appendWithNSString:[stringWriter description]]; | |
} | |
JavaUtilLoggingIOSLogHandler_logWithNSString_withInt_(self, [sb description], aslLevel); | |
} | |
- (void)logWithNSString:(NSString *)logMessage | |
withInt:(jint)aslLevel { | |
JavaUtilLoggingIOSLogHandler_logWithNSString_withInt_(self, logMessage, aslLevel); | |
} | |
+ (const J2ObjcClassInfo *)__metadata { | |
static const J2ObjcMethodInfo methods[] = { | |
{ "init", NULL, 0x1, -1, -1, -1, -1, -1, -1 }, | |
{ "close", "V", 0x1, -1, -1, -1, -1, -1, -1 }, | |
{ "flush", "V", 0x1, -1, -1, -1, -1, -1, -1 }, | |
{ "publishWithJavaUtilLoggingLogRecord:", "V", 0x1, 0, 1, -1, -1, -1, -1 }, | |
{ "logWithNSString:withInt:", "V", 0x102, 2, 3, -1, -1, -1, -1 }, | |
}; | |
static const J2ObjcFieldInfo fields[] = { | |
{ "IOS_LOG_MANAGER_DEFAULTS", "LNSString;", .constantValue.asLong = 0, 0x18, -1, 4, -1, -1 }, | |
{ "ASLCLIENT", "LNSString;", .constantValue.asLong = 0, 0x1a, -1, 5, -1, -1 }, | |
}; | |
static const void *ptrTable[] = { "publish", "LJavaUtilLoggingLogRecord;", "log", "LNSString;I", &JavaUtilLoggingIOSLogHandler_IOS_LOG_MANAGER_DEFAULTS, &JavaUtilLoggingIOSLogHandler_ASLCLIENT, "LJavaUtilLoggingIOSLogHandler_IOSLogFormatter;" }; | |
static const J2ObjcClassInfo _JavaUtilLoggingIOSLogHandler = { "IOSLogHandler", "java.util.logging", ptrTable, methods, fields, 7, 0x0, 5, 2, -1, 6, -1, -1, -1 }; | |
return &_JavaUtilLoggingIOSLogHandler; | |
} | |
@end | |
void JavaUtilLoggingIOSLogHandler_init(JavaUtilLoggingIOSLogHandler *self) { | |
JavaUtilLoggingHandler_init(self); | |
[self setFormatterWithJavaUtilLoggingFormatter:create_JavaUtilLoggingIOSLogHandler_IOSLogFormatter_init()]; | |
} | |
JavaUtilLoggingIOSLogHandler *new_JavaUtilLoggingIOSLogHandler_init() { | |
J2OBJC_NEW_IMPL(JavaUtilLoggingIOSLogHandler, init) | |
} | |
JavaUtilLoggingIOSLogHandler *create_JavaUtilLoggingIOSLogHandler_init() { | |
J2OBJC_CREATE_IMPL(JavaUtilLoggingIOSLogHandler, init) | |
} | |
void JavaUtilLoggingIOSLogHandler_logWithNSString_withInt_(JavaUtilLoggingIOSLogHandler *self, NSString *logMessage, jint aslLevel) { | |
// Add stderr as a log file, so that log messages are seen on the debug log, | |
// and not just the device log. | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
asl_add_log_file(NULL, STDERR_FILENO); | |
}); | |
NSThread *currentThread = [NSThread currentThread]; | |
NSMutableDictionary *threadData = [currentThread threadDictionary]; | |
ASLClientHolder *logClient = [threadData objectForKey:JavaUtilLoggingIOSLogHandler_ASLCLIENT]; | |
if (!logClient) { | |
aslclient aslClient = asl_open([[currentThread name] UTF8String], | |
[[[NSBundle mainBundle] bundleIdentifier] UTF8String], ASL_OPT_NO_DELAY | ASL_OPT_STDERR); | |
logClient = AUTORELEASE([[ASLClientHolder alloc] initWithClient:aslClient]); | |
[threadData setObject:logClient forKey:JavaUtilLoggingIOSLogHandler_ASLCLIENT]; | |
} | |
asl_log(logClient->_client, NULL, aslLevel, "%s", [logMessage UTF8String]); | |
} | |
J2OBJC_CLASS_TYPE_LITERAL_SOURCE(JavaUtilLoggingIOSLogHandler) | |
@implementation JavaUtilLoggingIOSLogHandler_IOSLogFormatter | |
- (NSString *)formatWithJavaUtilLoggingLogRecord:(JavaUtilLoggingLogRecord *)record { | |
return [self formatMessageWithJavaUtilLoggingLogRecord:record]; | |
} | |
J2OBJC_IGNORE_DESIGNATED_BEGIN | |
- (instancetype)init { | |
JavaUtilLoggingIOSLogHandler_IOSLogFormatter_init(self); | |
return self; | |
} | |
J2OBJC_IGNORE_DESIGNATED_END | |
+ (const J2ObjcClassInfo *)__metadata { | |
static const J2ObjcMethodInfo methods[] = { | |
{ "formatWithJavaUtilLoggingLogRecord:", "LNSString;", 0x1, 0, 1, -1, -1, -1, -1 }, | |
{ "init", NULL, 0x0, -1, -1, -1, -1, -1, -1 }, | |
}; | |
static const void *ptrTable[] = { "format", "LJavaUtilLoggingLogRecord;", "LJavaUtilLoggingIOSLogHandler;" }; | |
static const J2ObjcClassInfo _JavaUtilLoggingIOSLogHandler_IOSLogFormatter = { "IOSLogFormatter", "java.util.logging", ptrTable, methods, NULL, 7, 0x8, 2, 0, 2, -1, -1, -1, -1 }; | |
return &_JavaUtilLoggingIOSLogHandler_IOSLogFormatter; | |
} | |
@end | |
void JavaUtilLoggingIOSLogHandler_IOSLogFormatter_init(JavaUtilLoggingIOSLogHandler_IOSLogFormatter *self) { | |
JavaUtilLoggingFormatter_init(self); | |
} | |
JavaUtilLoggingIOSLogHandler_IOSLogFormatter *new_JavaUtilLoggingIOSLogHandler_IOSLogFormatter_init() { | |
J2OBJC_NEW_IMPL(JavaUtilLoggingIOSLogHandler_IOSLogFormatter, init) | |
} | |
JavaUtilLoggingIOSLogHandler_IOSLogFormatter *create_JavaUtilLoggingIOSLogHandler_IOSLogFormatter_init() { | |
J2OBJC_CREATE_IMPL(JavaUtilLoggingIOSLogHandler_IOSLogFormatter, init) | |
} | |
J2OBJC_CLASS_TYPE_LITERAL_SOURCE(JavaUtilLoggingIOSLogHandler_IOSLogFormatter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment