//
//  YCKLog.h
//  YCKit
//
//  Created by 徐家骏 on 2017/6/15.
//  Copyright © 2017年 徐家骏. All rights reserved.
//

#import <Foundation/Foundation.h>

extern BOOL gEnableConsoleLog;

static NSString * const sNotificationNameLogCacheFull = @"ycklogCacheFull";

typedef NS_ENUM(int, YCKLogLevel) {
    YCKLogLevel_Error = 0,
    YCKLogLevel_Warning,
    YCKLogLevel_Info,
    YCKLogLevel_Debug,
    YCKLogLevel_Verbose,
};

//---------------------------------------------------------------------------------

#ifdef __cplusplus
extern "C"
{
#endif
    
    void YCKPrintLog(YCKLogLevel level, const char *func, int line, NSString *logEntry);
    
    NSString * YCKGetAllLogs(void);
    NSString * YCKGetAllLogsAndClean(void);

    NSArray * YCKGetAllLogsList(void);
    
    void YCKClearAllLogs(void);
    
#ifdef __cplusplus
}
#endif


//---------------------------------------------------------------------------------

#if defined(DEBUG) || defined(FORCE_LOG)
#define ASSERT(...) do { @try { NSAssert(__VA_ARGS__); } @catch (NSException *exception){} } while(0)
#else
#define ASSERT(...)
#endif

#define LOGTemplate(level, ...) \
do { \
YCKPrintLog(level, __PRETTY_FUNCTION__, __LINE__, \
[NSString stringWithFormat:@__VA_ARGS__]); \
} while(0)

#define LOGE(...)   LOGTemplate(YCKLogLevel_Error    , __VA_ARGS__)
#define LOGW(...)   LOGTemplate(YCKLogLevel_Warning  , __VA_ARGS__)
#define LOGI(...)   LOGTemplate(YCKLogLevel_Info     , __VA_ARGS__)
#define LOGD(...)   LOGTemplate(YCKLogLevel_Debug    , __VA_ARGS__)

#ifdef DEBUG
#define LOGV(...)   LOGTemplate(YCKLogLevel_Verbose  , __VA_ARGS__)
#else
#define LOGV(...)   do { } while(0)
#endif

#define YCTRACECMD(...) \
do { \
YCKPrintLog(YCKLogLevel_Debug, __PRETTY_FUNCTION__, __LINE__, \
[NSString stringWithFormat:@"%@|%@", NSStringFromSelector(_cmd), \
[NSString stringWithFormat:@__VA_ARGS__]]); \
} while(0)
