//
//  aplog_helper.m
//  Portal
//
//  Created by qiwei on 01/02/2018.
//  Copyright © 2018 Alipay. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <objc/runtime.h>

static BOOL aptempdebugloghelper_method_exchangeImplementations_instance(Class origCls, SEL origSEL, Class newCls, SEL newSEL)
{
    Method origMethod = class_getInstanceMethod(origCls, origSEL);
    Method newMethod = class_getInstanceMethod(newCls, newSEL);
    
    if (!origMethod || !newMethod)
    {
        return NO;
    }
    
    const char *origType = method_getTypeEncoding(origMethod);
    const char *newType = method_getTypeEncoding(newMethod);
    
    IMP origIMP = class_replaceMethod(origCls, origSEL, method_getImplementation(newMethod), newType);
    if (origIMP)
    {
        class_replaceMethod(newCls, newSEL, origIMP, origType);
    }
    else
    {
        return NO;
    }
    
    return YES;
}

@interface APFileLog : NSObject
+(instancetype) sharedInstance;
-(BOOL) writeAesFileLog:(NSString *)logString;
@end

@interface APFileLog (DebugLog)
@end

@implementation APFileLog (DebugLog)
+ (void)load {
    aptempdebugloghelper_method_exchangeImplementations_instance([self class], @selector(writeAesFileLog:), [self class], @selector(replaced_writeAesFileLog:));
}
- (void)replaced_writeAesFileLog:(NSString*)str{
    NSLog(@"[debuglog] %@",str);
    [self replaced_writeAesFileLog:str];
}

@end


