自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

IOS應(yīng)用中使用SimpleLogger日志分類

移動(dòng)開發(fā) iOS
本文介紹的是IOS應(yīng)用中使用SimpleLogger日志分類,主要介紹了IOS應(yīng)用程序中的日志分類實(shí)例,來看內(nèi)容。

IOS應(yīng)用中使用SimpleLogger日志分類是本文要介紹的內(nèi)容,主要實(shí)現(xiàn)IOS中的日志分類一個(gè)實(shí)例,那么來看詳細(xì)內(nèi)容。

在壇子里看到一篇IOS日志管理的內(nèi)容,與友們來分享一下。之前做java的時(shí)候一直用Log4j做日志的分類,但是現(xiàn)在做iphone有一段時(shí)間了,一直用NSLog做日志,但是我們?cè)陂_發(fā)過程中需要一些強(qiáng)大的日志功能,例如對(duì)日志level的控制,對(duì)行號(hào)和文件名的打印等等。有一個(gè)開源的Log4Cocoa。

學(xué)習(xí)Object-C 和 iPhone也有將近兩個(gè)月了,幾乎任何講Object-C的書第一章就會(huì)用到NSLog這個(gè)函數(shù),這個(gè)函數(shù)可以向Console輸出一些信息,方便我們跟蹤程序的運(yùn)行過程??墒俏以谧鲆恍﹊Phone的開發(fā)的時(shí)候,卻需要一些稍微強(qiáng)大的日志功能,譬如文件名,行號(hào),對(duì)一些日志Level的控制。我在Google上找了一下,有個(gè)Log4Cocoa的,好像是想做成Log4j的功能??墒俏移綍r(shí)的需求不需要那么強(qiáng)大,而且我很不喜歡殺雞用牛刀,于是我自己寫了一個(gè)簡(jiǎn)單的日志庫SimpleLogger。

其實(shí)這個(gè)不能算庫,說白了就是SimpleLogger.h和SimpleLogger.m兩個(gè)文件,夠簡(jiǎn)單吧。我定義了一些常用的宏,譬如DEBUG, ENTER, RETURN,大家可以看源代碼,也可以直接看MyLogger.m的示例,就知道怎么用了。這個(gè)日志庫可以支持iPhone和MacOSX的開發(fā),不過它不是線程安全的(iPhone沒有這個(gè)問題)。

[使用方法]    

先看看下面的代碼:

  1. #import <Foundation/Foundation.h>     
  2. #import "SimpleLogger.h"     
  3.     
  4. int testLogger()     
  5. {     
  6.     ENTER(@"testLogger()");     
  7.     int rst = 10;     
  8.     RETURN(-rst, @"%d", -rst);     
  9. }     
  10.     
  11. int main (int argc, const char * argv[]) {     
  12.     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];     
  13.     [SimpleLogger getLogger];     
  14.          
  15.     //insert code here     
  16.     int i = 10;     
  17.     INFO(@"i is %d", i);     
  18.     i = -100;     
  19.     INFO(@"i is %d", i);            
  20.     testLogger();     
  21.     [pool drain];     
  22.     [[SimpleLogger getLogger]release];     
  23.     return 0;      
  24. }    
  25.  
  26. #import <Foundation/Foundation.h> 
  27. #import "SimpleLogger.h"  
  28.  
  29. int testLogger()  
  30. {  
  31.     ENTER(@"testLogger()");  
  32.     int rst = 10;  
  33.     RETURN(-rst, @"%d", -rst);  
  34. }  
  35.  
  36. int main (int argc, const char * argv[]) {  
  37.     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];  
  38.     [SimpleLogger getLogger];  
  39.       
  40.     //insert code here  
  41.     int i = 10;  
  42.     INFO(@"i is %d", i);  
  43.     i = -100;  
  44.     INFO(@"i is %d", i);         
  45.     testLogger();  
  46.     [pool drain];  
  47.     [[SimpleLogger getLogger]release];  
  48.     return 0;   

使用方法也非常簡(jiǎn)單

(1)把SimpleLogger.h和SimpleLogger.m加到你的項(xiàng)目中

(2)調(diào)用[[SimpleLogger getLogger]setLogLevelSetting:SOME_LEGEL];(可選的,默認(rèn)是SLLE_MAJOR)

(3)最后調(diào)用[[SimpleLogger getLogger]release]

(4)常用方法:

  1. ENTER(@"method name");       
  2. INFO(@"The count of array is %d", [array count]);       
  3. DEBUG(@"The person's name is %@", person.name);       
  4. ERROR(@"Impossible get into this branch");       
  5. RETURN(rst, @"%d", rst); //rst就是返回值      
  6.  LOG(SLL_DETAILED, @"This log is very detailed with value %d", value);       
  7.  [[SimpleLogger getLogger]setLogLevelSetting:SLLS_MINOR]; //設(shè)置日志級(jí)別  

下載類庫:http://wangjun.easymorse.com/wp-content/tools/SimpleLogger.zip

MyLogger.tar:http://dl.iteye.com/topics/download/2898cb63-c4c6-3042-be73-2e173cac2a64

小結(jié):iOS應(yīng)用中使用SimpleLogger日志分類的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2012-02-13 14:22:22

MonoTouchiOS應(yīng)用Visual Stud

2012-02-13 14:10:11

MonoTouchiOS應(yīng)用Visual Stud

2011-07-18 10:00:47

iPhone iOS Visual Stu

2011-07-18 10:21:04

iOS Visual Stu iphone

2015-09-01 10:32:11

2015-09-01 14:29:33

2011-09-02 19:24:20

SqliteIOS應(yīng)用數(shù)據(jù)庫

2014-12-22 09:51:06

Linuxlogwatch

2011-08-17 14:57:31

iPhone應(yīng)用視頻播放

2021-02-25 11:19:37

谷歌Android開發(fā)者

2022-05-11 10:58:11

MetricKitiOS13系統(tǒng)崩潰診斷

2023-12-22 09:11:45

AndroidNFC移動(dòng)開發(fā)

2022-02-08 17:07:54

Spring BooSpring Aop日志記錄

2011-09-06 16:30:32

iOS系統(tǒng)靜態(tài)鏈接庫

2012-05-04 23:15:43

iOS

2009-09-22 12:17:59

ibmdwLotus

2022-09-26 12:28:16

OpenGLAPI使用移動(dòng)應(yīng)用

2016-08-11 10:43:56

2024-09-05 15:42:34

PyTorch回調(diào)日志

2011-07-21 14:50:06

Core Data SQL
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)