BBASMsConsoleLogDef.h 5.13 KB
//
//  BBASMsConsoleLogDef.h
//  SWAN
//
//  Created by baidu on 2018/10/26.
//  Copyright © 2018 baidu. All rights reserved.
//

#ifndef BBASMsConsoleLogDef_h
#define BBASMsConsoleLogDef_h

#ifdef __cplusplus
extern "C" {
#endif

typedef NS_ENUM(NSUInteger, BBASMConsoleLogLevel) {
    /// v 详细(表示所有可能的日志,默认级别)
    BBASMConsoleLogLevelVerbose = 1,
    /// d 调试(表示所有合理的调试用日志)
    BBASMConsoleLogLevelInfo   = 2,
    /// d 调试(表示所有合理的调试用日志)
    BBASMConsoleLogLevelDebug  = 3,
    /// w 警告(表示可能有问题,还没发生错误)
    BBASMConsoleLogLevelWarning= 4 ,
    /// e 错误(表示有问题并导致出错)
    BBASMConsoleLogLevelError  = 5
};

typedef NS_ENUM(NSInteger, BBASMInfoLogActionType)
{
    BBASMInfoLogCreate         = 1,
    BBASMInfoLogBack           = 2,
    BBASMInfoLogForward        = 3,
    BBASMInfoLogOther          = 4,
};

typedef NS_ENUM(NSInteger, BBASMLogLevel)
{
    BBASMLogLevelInfo,      //info日志 (表示正常使用时的日志)
    BBASMLogLevelWarning,   //Warning日志 (表示需要强调,或可能有问题,还没发生错误)
    BBASMLogLevelError      // Error日志 (表示有问题并导致出错)
};

//
__used extern void BBAAddConsoleLog(BBASMConsoleLogLevel type,
                                    NSString *module,
                                    const char *filename,
                                    int lineNumber,
                                    NSString *content,
                                    NSString *appID);

__used extern void BBAAddInfoLog(NSString *module,
                                 NSInteger actionType,
                                 NSString *action,
                                 NSString *from,
                                 NSString *to,
                                 NSString *content,
                                 NSString *appID);
/**
 * @brief  yalog日志系统
 *
 * @param appID xcxid
 * @param level 日志等级
 * @param module 模块名字或者类名
 * @param msg 错误信息
 * @param filename 类名
 * @param lineNumber 行号
 */
__used extern void BBASMLogToFile(NSString *appID,
                                  BBASMLogLevel level,
                                  NSString *module,
                                  NSString *msg,
                                  const char *filename,
                                  int lineNumber);

/***************    普通日志系统调用宏 同时写入sConsole和日志系统        ***************/
// level:日志级别,content:日志信息,module:模块名字(传空为默认类名),appid:xcxid

#define BBASM_INFO_LOG(level, content, module, appID) \
({if (level == BBASMLogLevelInfo) {BBAAddInfoLog(module, BBASMConsoleLogLevelInfo, nil, nil, nil, content, appID);}\
else if (level == BBASMLogLevelWarning) {BBAAddInfoLog(module, BBASMConsoleLogLevelWarning, nil, nil, nil, content, appID);}\
else {BBAAddInfoLog(module, BBASMConsoleLogLevelError, nil, nil, nil, content, appID);}\
BBASMLogToFile(appID, level, module, content, __FILENAME__, __LINE__);\
})


/***************    端能力日志系统调用宏,同时写入sConsole和日志系统      ***************/ 
// level:日志级别,content:日志信息,module:模块名字(传空为默认类名),action 具体的调用,appid:xcxid
#define BBASM_INFO_LOG_ACTION(level, content, module, action, appID) \
({if (level == BBASMLogLevelInfo) {BBAAddInfoLog(module, BBASMConsoleLogLevelInfo, action, nil, nil, content, appID);}\
else if (level == BBASMLogLevelWarning) {BBAAddInfoLog(module, BBASMConsoleLogLevelWarning, action, nil, nil, content, appID);}\
else {BBAAddInfoLog(module, BBASMConsoleLogLevelError, action, nil, nil, content, appID);}\
BBASMLogToFile(appID, level, module, [NSString stringWithFormat:@"%@, %@", action, content], __FILENAME__, __LINE__);\
})


/***************   私有日志系统调用宏,只写入日志系统     ***************/
// level:日志级别,content:日志信息,module:模块名字(传空为默认类名),appid:xcxid
#define BBASM_Log_To_File(level, content, module, appID) BBASMLogToFile(appID, level, module, content, __FILENAME__, __LINE__)


/***************    sConsole日志        ***************/
/// verbose日志 (表示所有可能的日志,默认级别) 双端对齐
#define BBASM_VERBOSE_LOG(content, module, appID) \
({ \
    BBAAddConsoleLog(1, module, __FILE__, __LINE__, content, appID); \
})

/// debug日志 (表示所有合理的调试用日志)双端对齐
#define BBASM_DEBUG_LOG(content, module, appID) \
({ \
    BBAAddConsoleLog(3, module, __FILE__, __LINE__, content, appID); \
})


/***************    日志系统相关        ***************/
/// 获取类名
#define __FILENAME__ (strrchr(__FILE__,'/')+1)


#ifdef __cplusplus
}
#endif
/// 通用的log id key
extern NSString *const BBASMLogCommonServiceID;
/// xcx jsVer key
extern NSString *const BBASMLogServiceInfoJsVer;
/// xcx extentionVer
extern NSString *const BBASMLogServiceInfoExtentionVer;
/// xcx appVer
extern NSString *const BBASMLogServiceInfoAppPkgVer;

#endif /* BBASMsConsoleLogDef_h */