Use of NSLogger


  • Use: used to monitor the app log, from the Xcode console MAC interface is as follows:
    Use of NSLogger
    version of the QQ client log
  • Use NSLogger Viewer MAC installation steps: analyzing the end of the log, the log can be passed through the network, the default log
    PS computer to accept all the local network of a: so when I installed NSLogger Viewer found it listens to the macQQ log, macQQ seems to have use NSLogger ah, ha ha in the project with NSLogger framework. Support pod #import into the “NSLogger.h” header file (some of my): add a macro, free switch Xcode console and NSLogger use NSLogger to print notes: / / next line cancel; use the Xcode console: notes under a line of //#define NSLOGGER_CLIENT into NSLogger.h #ifdef NSLOGGER_CLIENT #import of “NSLogger.h” / / NSLogger #else #ifdef DEBUG (#define LoggerError level NSLog (__V,…) A_ARGS__ #define LoggerApp (level),…) NSLog (__VA_ARGS__) #define LoggerView (level,…) NSLog (__VA_ARGS__) #define LoggerService (level,…) NSLog (__VA_ARGS__) #define LoggerModel (level,…) NSLog (__VA_ARGS__) # define LoggerData (level,…) NSLog (__VA_ARGS__) #define LoggerNetwork (level,… NSLog (__VA_ARGS__) #define) LoggerLocation (level,…) NSLog (__VA_ARGS__) #define LoggerPush (level,…) NSLog (__VA_ARGS__) #define LoggerFile (level,…) NSLog (__VA_ARGS__) #define LoggerSharing (level,…) NSLog (__VA_ARGS__) #define LoggerAd (level,…) NSLog (__VA_ARGS__) #e LSE #define NSLog (…) while (0) #define LoggerError ({} {}…) while (0) #define LoggerApp (level,…) while (0) #define LoggerView ({} {}…) while (0) #define LoggerService (…) while (0) #define LoggerModel ({} {}…) while (0) #define LoggerData (…) while (0) #define LoggerNetwork ({} {}…) while (0) #define LoggerLocation (…) while (0) #define LoggerPush ({} {}…) while (0) #define LoggerFile (…) while (0) define LoggerSharing (# {} {}…) while (0) #define LoggerAd (… While (0) #endif #endif) {}

Principle:

The following macros are defined in the NSLogger.h file

#define NSLog (...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, @ "NSLog", 0, __VA_ARGS__) #define LoggerError (level,...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, Error, level @ __VA_ARGS__, #define) LoggerApp (level,...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, @ App "level, __VA_ARGS__, #define) LoggerView (level,...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, View, level @ __VA_ARGS__, #) define LoggerService (level,...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, Service, @ level, __VA_ARGS__ #define LoggerModel (level), LogMessageF (...) __FILE__, __LINE__, __FUNCTION__, Model, level @ __VA_ARGS__), #define LoggerData (level,...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, Data, level @ __VA_ARGS__, #define) LoggerNetwork (level,...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, Network, level @ __VA_ARGS__, #define) LoggerLocation (level,...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, Location, level, @ __VA_ARGS__ #define LoggerPush (level),...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, Push, level @ __VA_ARGS__, #define) LoggerFile (level,...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, File, level @ __VA_ARGS__, #define) LoggerSharing (level,...) LogMessageF (__FILE__, __LINE__, __FUNCTION__. @ "Sharing", level __VA_ARGS__, #define LoggerAd (level) LogMessageF (__FILE_,...) _, __LINE__, __FUNCTION__, Ad @ and Stat, level, __VA_ARGS__)

among

#define NSLog (...) LogMessageF (__FILE__, __LINE__, __FUNCTION__, @ NSLog, 0, __VA_ARGS__)

The direct replacement of all NSLog for LogMessageF
into the LogMessage found him to be one of the following methods

Void LogMessageF (const char *filename, int lineNumber, const char *functionName, NSString *domain, int level, NSString, *format,...) {va_list args; va_start (args, format); LogMessageTo_internal (NULL, filename, lineNumber, functionName, domain, level, format, args); va_end (args);}

Which LogMessageTo_internal (NULL, filename, lineNumber, functionName, domain, level, format, args) is to send data to the network

At the same time, the NSLogger.h file also defines a lot of other macros, according to the name may be able to guess what they use
ps: more features to be explored, do not want to write 2333~

A network request method (please ignore cases code inside a bunch of disgusting things, just want to explain the use of NSLogger):

- (void) sendRequest: (NSMutableDictionary * mutableDic) url: (NSString * URL) (progress: (void ^) (NSProgress *uploadProgress) uploadProgressBack compelete: (void) (^) (BOOL success, NSDictionary *responseObject compelete (Manager)) {if = = Nil) {manager} = [AFHTTPSessionManager manager]; manager.responseSerializer.acceptableContentTypes setWithObjects:@ [NSSet = "text/html" @ @, "text/plain", "application/json", nil] [manager.requestSerializer; setValue:@ "ture" forHTTPHeaderField:@ "ifModified"]; [manager.requestSerializer setValue:@ "IOS" forHTTPHeaderField:@ "app"]; NSMutableDictionary *paramDic = nil; if (mutableDic) {paramDic = [[NSMutableDictionary alloc] initWithDictionar Y:mutableDic];} else {paramDic = [[NSMutableDictionary alloc] init] [paramDic setValue:[[JFUserInfo shareUserInfo] getToken] forKey:kUSERTOKE];}; [paramDic setValue:[NSString appVersion] forKey:kCLIENTVERSION] NSLogger LoggerService; / / use (2, @ "% @", URL); LoggerData (2, paramDic = @% @ ", paramDic); [manager POST:url parameters:paramDic progress:^ (NSProgress * _Nonnull uploadProgress) {if (uploadProgressBack) uploadProgressBack (uploadProgress) {};} success:^ (NSURLSessionDataTask * _Nonnull task, ID _Nullable responseObject (LoggerData) {/ / NSLogger 3, @ responseObject =% @", responseObject); NSLog (@ "errmsg:%@" (NSDictionary * RES) PonseObject[@ "errmsg"]); NSDictionary *responseDic = (NSDictionary * responseObject); NSNumber *code responseDic[@ = "errCode"]; if ([code integerValue] [code integerValue] || = = 2000001 = = -4) {// re login NSLog (@ "% @: error request", responseDic[@ "errmsg"]); [[AppDelegate sharedAppDelegate] enterLoginUI]; return;} if (compelete) {if ([code integerValue] = = 0) {compelete (YES, responseDic);}else if ([code integerValue] < 0) {/ / NSLog ("% @, @% @ error request: mutableDic,% @" URL, responseDic[@ "errmsg"]); NSMutableDictionary * DIC = [NSMutableDictionary dictionary]; [dic setValu E:JFERRORMSG forKey:@ "errmsg"]; [dic setValue:[NSNumber numberWithInt:-1] forKey:@ "errCode"]; compelete (NO, DIC);}else{compelete (NO, responseDic);}}} failure:^ (NSURLSessionDataTask * _Nullable task NSError * _Nonnull error) {/ / if (compelete) {NSMutableDictionary = [NSMutableDictionary * DIC dictionary] [dic setValue:JFERRORMSG forKey:@ "; errmsg [dic setValue:[NSNumber numberWithInt:-1] forKey:@"; "errCode"]; compelete (NO, DIC); / /}]}};