이 CocoaLumberjack 프레임 워크를 사용하여 모든 메시지를 Objective-C 디자인에 기록합니다. 이제 모든 오류를 하나의 파일에 기록하고 다른 모든 메시지는 다른 파일에 기록하려고합니다. 이 정보를 필터하기 위해 포맷터를 사용할 수 있다는 것을 알고 있습니다. AppDelegate에서 두 개의 DDFileLogger 인스턴스를 만들었지 만이 두 로거는 동일한 파일에 계속 쓰고 있습니다. 두 로거가 두 개의 다른 파일에 쓰도록 로깅 대상을 지정할 수있는 방법이 있는지 궁금합니다.CocoaLumberjack FileLogger 여러 파일에 로깅
답변
이 작업을 얻으려면 각 DDFileLogger를 각각의 DDFileManager를 설정하고 각각에 대해 별도의 로그 디렉토리 경로를 지정해야합니다. DDLogFileManager는 로그 디렉토리 경로를 사용하여 어떤 파일을 로깅할지 결정하므로 동일한 디렉토리를 가리키는 두 개의 파일이있는 경우 동일한 로그 파일에 기록됩니다. 따라서 핵심은 각 로그에 대해 별도의 디렉토리를 사용하는 것입니다. "한"과 "2": 두 개의 서로 다른 로그 유형의
는 는 여전히 로깅을 수행하는 매크로를 정의 할 필요가 물론// Set the base log directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *baseDir = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *logsDirectory = [baseDir stringByAppendingPathComponent:@"Logs"];
// set up file logger One to log to subdirectory "One"
DDLogFileManagerDefault *fileManagerOne = [[DDLogFileManagerDefault alloc] initWithLogsDirectory:[logsDirectory stringByAppendingPathComponent:@"One"]];
DDFileLogger *loggerOne = [[DDFileLogger alloc] fileManagerOne];
// Use the filter formatter to make sure only "One" logs go to the "One" log files
ContextWhitelistFilterLogFormatter *formatterOne = [[ContextWhitelistFilterLogFormatter alloc] init];
[formatterOne addToWhitelist:LOG_CONTEXT_ONE];
[loggerOne formatterOne];
[DDLog loggerOne];
// set up file logger Two to log to subdirectory "Two"
DDLogFileManagerDefault *fileManagerTwo = [[DDLogFileManagerDefault alloc] initWithLogsDirectory:[logsDirectory stringByAppendingPathComponent:@"Two"]];
DDFileLogger *loggerTwo = [[DDFileLogger alloc] fileManagerTwo];
// Use the filter formatter to make sure only "Two" logs go to the "Two" log files
ContextWhitelistFilterLogFormatter *formatterTwo = [[ContextWhitelistFilterLogFormatter alloc] init];
[formatterTwo addToWhitelist:LOG_CONTEXT_TWO];
[loggerTwo formatterTwo];
[DDLog loggerTwo];
:
#define LOG_CONTEXT_ONE 1
#define LOG_CONTEXT_TWO 2
#define LogOne(frmt, ...) SYNC_LOG_OBJC_MACRO(0, 0, LOG_CONTEXT_ONE, frmt, ##__VA_ARGS__)
#define LogTwo(frmt, ...) SYNC_LOG_OBJC_MACRO(0, 0, LOG_CONTEXT_TWO, frmt, ##__VA_ARGS__)
이 일 것입니다 나를 위해.
기본 컨텍스트 0을 사용하고 loggerOne 코드를 추가하여이 작업을 단순화 할 수도 있습니다. 그런 다음 컨텍스트 0에 대한 DDContextWhitelistFilterLogFormatter를 기본 파일 로거에 추가하기 만하면됩니다. – dbainbridge
SYNC_LOG_OBJC_MACRO의 암시 적 선언은 c99에서 허용되지 않습니다. 아무도 이것에 관해서 도울 수 있습니까 ?? –
새로운 기능 (모든 로거에 대해 서로 다른 로그 수준)을 사용하여 매우 근접하게 달성 할 수 있습니다. https://github.com/robbiehanson/CocoaLumberjack/wiki/PerLoggerLogLevels을 참조하십시오. 두 파일 로거 (오류 수준 및 자세한 정보 표시가있는 파일 로거)를 만드는 것은 오류 로그가 두 파일에 모두 포함되므로 설명 된대로 정확하지 않습니다. 이것으로 충분합니까?
필자도이 작업이 필요하지만 중요한 것은 로깅을 개별 파일로 이동하는 것입니다. 두 파일에 모두 들어가면 적어도 내 목적을 저지합니다. – dbainbridge
나는 위의 상단 답변에 의견을 충분히 명성을 가지고 있지 않지만, 여기에서 최신 CocoaLumberjack와 함께 작동 KabukiAdam의 대답의 버전입니다 :
// Set the base log directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *baseDir = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *logsDirectory = [baseDir stringByAppendingPathComponent:@"Logs"];
// set up file logger One to log to subdirectory "One"
DDLogFileManagerDefault *fileManagerOne = [[DDLogFileManagerDefault alloc] initWithLogsDirectory:[logsDirectory stringByAppendingPathComponent:@"One"]];
DDFileLogger *loggerOne = [[DDFileLogger alloc] initWithLogFileManager:fileManagerOne];
// Use the filter formatter to make sure only "One" logs go to the "One" log files
ContextWhitelistFilterLogFormatter *formatterOne = [[ContextWhitelistFilterLogFormatter alloc] init];
[formatterOne addToWhitelist:LOG_CONTEXT_ONE];
[loggerOne setLogFormatter:formatterOne];
[DDLog addLogger:loggerOne];
// set up file logger One to log to subdirectory "Two"
DDLogFileManagerDefault *fileManagerTwo = [[DDLogFileManagerDefault alloc] initWithLogsDirectory:[logsDirectory stringByAppendingPathComponent:@"Two"]];
DDFileLogger *loggerTwo = [[DDFileLogger alloc] initWithLogFileManager:fileManagerTwo];
// Use the filter formatter to make sure only "Two" logs go to the "Two" log files ContextWhitelistFilterLogFormatter *formatterTwo = [[ContextWhitelistFilterLogFormatter alloc] init];
[formatterTwo addToWhitelist:LOG_CONTEXT_TWO];
[loggerTwo setLogFormatter:formatterTwo];
[DDLog addLogger:loggerTwo];
SYNC_LOG_OBJC_MACRO의 암시 적 선언은 c99에서 허용되지 않습니다. 아무도 이것에 관해서 도울 수 있습니까 ?? –
- 1. 여러 파일에 파이썬 로깅
- 2. Log4j 여러 파일에 로깅
- 3. iPhone의 파일에 로깅
- 4. Log4j 별도의 파일에 로깅
- 5. 다른 라이브러리의 CocoaLumberjack 및 NSLog
- 6. 플렉스의 로컬 파일에 로깅
- 7. 화면 및 파일에 로깅
- 8. 여러 프로세스에서 파이썬 로깅
- 9. 여러 파일로 파이썬 로깅
- 10. 의 log4j - 프로젝트 모듈에 따라 여러 로그 파일에 로깅
- 11. Log4j 공유 로그 파일에 로깅
- 12. 여러 응용 프로그램의 로깅 개요
- 13. 단일 logging.properties를 사용하여 다른 파일에 로깅
- 14. CocoaLumberjack 파일 및 콘솔이 다른 자세한 내용
- 15. CocoaLumberjack 및 ZXingWidget을 사용하는 아키텍처 i386에 대한 정의되지 않은 기호
- 16. 솔루션의 여러 프로젝트에 대한 로깅 구성
- 17. log4net을 사용하여 여러 어셈블리를 로깅
- 18. 여러 응용 프로그램 인스턴스 로깅
- 19. 여러 시스템에서 PerfMon 로깅 제어
- 20. 여러 노드에서 시간 로깅 모델링
- 21. LogFactory 및 오류 데이터베이스/텍스트 파일에 로깅
- 22. WriteToEventLog sql aspnet_db 로그 파일에 예외 로깅
- 23. JMX MBean 액세스를 로그 파일에 로깅
- 24. 로깅/구성 파일에 적합한 파일 형식은 무엇입니까?
- 25. Trace.axd의 데이터를 text/xml 파일에 로깅
- 26. 서버 로깅 - 데이터베이스 또는 로그 파일에 있습니까?
- 27. 하나의 파일에 로그인하도록 SSIS 로깅 구성
- 28. Python이 로깅 설정 파일에 filemode를 설정했습니다.
- 29. Rails3 별도의 파일에 SQL 로깅 출력
- 30. 별도의 파일에 정보 수준 항목 만 로깅
저도 같은 문제에 봉착는. [이 포스트] (http://stackoverflow.com/a/7762344/264775)에서 접근법을 시도했지만 디바이스 나 시뮬레이터에서 작동하지 않습니다. 작동 방식을 찾았습니까? – thegrinner
SWIFT 2.2 프로젝트에서 코코아 짐 잭과 하키를 통합하는 단계별 지침을 얻을 수있는 문서 또는 링크를 얻을 수 있습니까? 모든 링크와 하키 애플 리케이션 웹 사이트는 모든 구현을 objective-c로 보여줍니다. 감사! – Tejas