외규장각 도서 환수 모금 캠페인
BLOG main image
분류 전체보기 (45)
컴퓨팅환경 (18)
프로그래밍 (18)
놀이 (2)
잡담 (7)
«   2010/03   »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
10,014 Visitors up to today!
Today 7 hit, Yesterday 24 hit
daisy rss
meet me at me2DAY
나눔글꼴 내려받기
tistory
'logging'에 해당되는 글 2건
2009/05/20 17:26

환경변수 NSObjCMessageLoggingEnabled를 YES로 세팅하고 코코아 응용프로그램을 실행하면 응용프로그램에서 발생하는 모든 Objective-C 메세징을 로그파일에 써준다. 로그파일은 /tmp/msgSends-PID.

하지만, 이거는 도움이 될 수가 없다. 워낙 많은 메세징이 발생하기 때문... 원하는 것은 특정 부분에서 어떤 메세징이 발생하는지가 될 것이다.

소스코드상에서 다음과 같이 관심있는 부분 앞뒤로 메세지 로깅을 켜고 끌 수 있다.

instrumentObjcMessageSends(YES);

/* 메세징 로깅을 원하는 코드 */

instrumentObjcMessageSends(NO);

 

이 글은 스프링노트에서 작성되었습니다.

2008/12/19 15:04

가끔 메소드가 어떻게 호출되고 있는지 로그로 남겨서 확인해 보고 싶을 때가 있다. 매번 확인하고 싶은 메소드 시작부분마다 메소드 이름을 로그로 출력해 주는 코드를 끼워넣는 것은 좀 귀찮은 일이다. 그래서 매크로를 한번 만들어 봤다.

Log.h

#define LogMethod()   LogMethodBody(self, _cmd, __FILE__, __LINE__)
#define LogFunction() LogFunctionBody(__PRETTY_FUNCTION__, __FILE__, __LINE__)

Log.m

#import <Foundation/Foundation.h>


void LogMethodBody(id self, SEL _cmd, const char *file, int line)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    if (self == [self class])
    {
        NSLog(@"%@:%d: +[%@ %@]",
              [[NSString stringWithCString:file encoding:NSUTF8StringEncoding] lastPathComponent],
              line,
              NSStringFromClass(self),
              NSStringFromSelector(_cmd));
    }
    else
    {
        NSLog(@"%@:%d: -[%@ %@] (%p)",
              [[NSString stringWithCString:file encoding:NSUTF8StringEncoding] lastPathComponent],
              line,
              NSStringFromClass([self class]),
              NSStringFromSelector(_cmd),
              self);
    }

    [pool release];
}

void LogFunctionBody(const char *function, const char *file, int line)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSLog(@"%@:%d: %s()",
          [[NSString stringWithCString:file encoding:NSUTF8StringEncoding] lastPathComponent],
          line,
          function);

    [pool release];
}

이렇게 하면 삽질을 좀 줄일 수 있다. 흐흐.

이전 포스트에서 Objective-C 메소드의 경우 method signature라는 것이 있다는 설명을 했었다. 그래서 Objective-C Runtime API를 이용하면 메소드 호출시 넘어온 인자들까지 확인가능하다. 이 부분은 생략하도록 하겠다. ㅋㅋ

 

이 글은 스프링노트에서 작성되었습니다.

prev"" #1 next