OSSDDLog.m 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. // Software License Agreement (BSD License)
  2. //
  3. // Copyright (c) 2010-2016, Deusty, LLC
  4. // All rights reserved.
  5. //
  6. // Redistribution and use of this software in source and binary forms,
  7. // with or without modification, are permitted provided that the following conditions are met:
  8. //
  9. // * Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. //
  12. // * Neither the name of Deusty nor the names of its contributors may be used
  13. // to endorse or promote products derived from this software without specific
  14. // prior written permission of Deusty, LLC.
  15. // Disable legacy macros
  16. #ifndef OSSDD_LEGACY_MACROS
  17. #define OSSDD_LEGACY_MACROS 0
  18. #endif
  19. #import "OSSDDLog.h"
  20. #import <pthread.h>
  21. #import <dispatch/dispatch.h>
  22. #import <objc/runtime.h>
  23. #import <mach/mach_host.h>
  24. #import <mach/host_info.h>
  25. #import <libkern/OSAtomic.h>
  26. #import <Availability.h>
  27. #if TARGET_OS_IOS
  28. #import <UIKit/UIDevice.h>
  29. #endif
  30. #if !__has_feature(objc_arc)
  31. #error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
  32. #endif
  33. // We probably shouldn't be using DDLog() statements within the DDLog implementation.
  34. // But we still want to leave our log statements for any future debugging,
  35. // and to allow other developers to trace the implementation (which is a great learning tool).
  36. //
  37. // So we use a primitive logging macro around NSLog.
  38. // We maintain the NS prefix on the macros to be explicit about the fact that we're using NSLog.
  39. #ifndef OSSDD_DEBUG
  40. #define OSSDD_DEBUG NO
  41. #endif
  42. #define OSSNSLogDebug(frmt, ...) do{ if(OSSDD_DEBUG) NSLog((frmt), ##__VA_ARGS__); } while(0)
  43. // Specifies the maximum queue size of the logging thread.
  44. //
  45. // Since most logging is asynchronous, its possible for rogue threads to flood the logging queue.
  46. // That is, to issue an abundance of log statements faster than the logging thread can keepup.
  47. // Typically such a scenario occurs when log statements are added haphazardly within large loops,
  48. // but may also be possible if relatively slow loggers are being used.
  49. //
  50. // This property caps the queue size at a given number of outstanding log statements.
  51. // If a thread attempts to issue a log statement when the queue is already maxed out,
  52. // the issuing thread will block until the queue size drops below the max again.
  53. #ifndef OSSDDLOG_MAX_QUEUE_SIZE
  54. #define OSSDDLOG_MAX_QUEUE_SIZE 1000 // Should not exceed INT32_MAX
  55. #endif
  56. // The "global logging queue" refers to [DDLog loggingQueue].
  57. // It is the queue that all log statements go through.
  58. //
  59. // The logging queue sets a flag via dispatch_queue_set_specific using this key.
  60. // We can check for this key via dispatch_get_specific() to see if we're on the "global logging queue".
  61. static void *const GlobalLoggingQueueIdentityKey = (void *)&GlobalLoggingQueueIdentityKey;
  62. @interface OSSLoggerNode : NSObject
  63. {
  64. // Direct accessors to be used only for performance
  65. @public
  66. id <OSSDDLogger> _logger;
  67. OSSDDLogLevel _level;
  68. dispatch_queue_t _loggerQueue;
  69. }
  70. @property (nonatomic, readonly) id <OSSDDLogger> logger;
  71. @property (nonatomic, readonly) OSSDDLogLevel level;
  72. @property (nonatomic, readonly) dispatch_queue_t loggerQueue;
  73. + (OSSLoggerNode *)nodeWithLogger:(id <OSSDDLogger>)logger
  74. loggerQueue:(dispatch_queue_t)loggerQueue
  75. level:(OSSDDLogLevel)level;
  76. @end
  77. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78. #pragma mark -
  79. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  80. @interface OSSDDLog ()
  81. // An array used to manage all the individual loggers.
  82. // The array is only modified on the loggingQueue/loggingThread.
  83. @property (nonatomic, strong) NSMutableArray *_loggers;
  84. @end
  85. @implementation OSSDDLog
  86. // All logging statements are added to the same queue to ensure FIFO operation.
  87. static dispatch_queue_t _loggingQueue;
  88. // Individual loggers are executed concurrently per log statement.
  89. // Each logger has it's own associated queue, and a dispatch group is used for synchrnoization.
  90. static dispatch_group_t _loggingGroup;
  91. // In order to prevent to queue from growing infinitely large,
  92. // a maximum size is enforced (DDLOG_MAX_QUEUE_SIZE).
  93. static dispatch_semaphore_t _queueSemaphore;
  94. // Minor optimization for uniprocessor machines
  95. static NSUInteger _numProcessors;
  96. /**
  97. * Returns the singleton `DDLog`.
  98. * The instance is used by `DDLog` class methods.
  99. *
  100. * @return The singleton `DDLog`.
  101. */
  102. + (instancetype)sharedInstance {
  103. static id sharedInstance = nil;
  104. static dispatch_once_t onceToken;
  105. dispatch_once(&onceToken, ^{
  106. sharedInstance = [[self alloc] init];
  107. });
  108. return sharedInstance;
  109. }
  110. /**
  111. * The runtime sends initialize to each class in a program exactly one time just before the class,
  112. * or any class that inherits from it, is sent its first message from within the program. (Thus the
  113. * method may never be invoked if the class is not used.) The runtime sends the initialize message to
  114. * classes in a thread-safe manner. Superclasses receive this message before their subclasses.
  115. *
  116. * This method may also be called directly (assumably by accident), hence the safety mechanism.
  117. **/
  118. + (void)initialize {
  119. static dispatch_once_t OSSDDLogOnceToken;
  120. dispatch_once(&OSSDDLogOnceToken, ^{
  121. OSSNSLogDebug(@"OSSDDLog: Using grand central dispatch");
  122. _loggingQueue = dispatch_queue_create("oss.cocoa.lumberjack", NULL);
  123. _loggingGroup = dispatch_group_create();
  124. void *nonNullValue = GlobalLoggingQueueIdentityKey; // Whatever, just not null
  125. dispatch_queue_set_specific(_loggingQueue, GlobalLoggingQueueIdentityKey, nonNullValue, NULL);
  126. _queueSemaphore = dispatch_semaphore_create(OSSDDLOG_MAX_QUEUE_SIZE);
  127. // Figure out how many processors are available.
  128. // This may be used later for an optimization on uniprocessor machines.
  129. _numProcessors = MAX([NSProcessInfo processInfo].processorCount, (NSUInteger) 1);
  130. OSSNSLogDebug(@"DDLog: numProcessors = %@", @(_numProcessors));
  131. });
  132. }
  133. /**
  134. * The `DDLog` initializer.
  135. * Static variables are set only once.
  136. *
  137. * @return An initialized `DDLog` instance.
  138. */
  139. - (id)init {
  140. self = [super init];
  141. if (self) {
  142. self._loggers = [[NSMutableArray alloc] initWithCapacity:4];
  143. #if TARGET_OS_IOS
  144. NSString *notificationName = @"UIApplicationWillTerminateNotification";
  145. #else
  146. NSString *notificationName = nil;
  147. // On Command Line Tool apps AppKit may not be avaliable
  148. #ifdef NSAppKitVersionNumber10_0
  149. if (NSApp) {
  150. notificationName = @"NSApplicationWillTerminateNotification";
  151. }
  152. #endif
  153. if (!notificationName) {
  154. // If there is no NSApp -> we are running Command Line Tool app.
  155. // In this case terminate notification wouldn't be fired, so we use workaround.
  156. atexit_b (^{
  157. [self applicationWillTerminate:nil];
  158. });
  159. }
  160. #endif /* if TARGET_OS_IOS */
  161. if (notificationName) {
  162. [[NSNotificationCenter defaultCenter] addObserver:self
  163. selector:@selector(applicationWillTerminate:)
  164. name:notificationName
  165. object:nil];
  166. }
  167. }
  168. return self;
  169. }
  170. /**
  171. * Provides access to the logging queue.
  172. **/
  173. + (dispatch_queue_t)loggingQueue {
  174. return _loggingQueue;
  175. }
  176. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  177. #pragma mark Notifications
  178. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  179. - (void)applicationWillTerminate:(NSNotification * __attribute__((unused)))notification {
  180. [self flushLog];
  181. }
  182. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  183. #pragma mark Logger Management
  184. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  185. + (void)addLogger:(id <OSSDDLogger>)logger {
  186. [self.sharedInstance addLogger:logger];
  187. }
  188. - (void)addLogger:(id <OSSDDLogger>)logger {
  189. [self addLogger:logger withLevel:OSSDDLogLevelAll]; // DDLogLevelAll has all bits set
  190. }
  191. + (void)addLogger:(id <OSSDDLogger>)logger withLevel:(OSSDDLogLevel)level {
  192. [self.sharedInstance addLogger:logger withLevel:level];
  193. }
  194. - (void)addLogger:(id <OSSDDLogger>)logger withLevel:(OSSDDLogLevel)level {
  195. if (!logger) {
  196. return;
  197. }
  198. dispatch_async(_loggingQueue, ^{ @autoreleasepool {
  199. [self lt_addLogger:logger level:level];
  200. } });
  201. }
  202. + (void)removeLogger:(id <OSSDDLogger>)logger {
  203. [self.sharedInstance removeLogger:logger];
  204. }
  205. - (void)removeLogger:(id <OSSDDLogger>)logger {
  206. if (!logger) {
  207. return;
  208. }
  209. dispatch_async(_loggingQueue, ^{ @autoreleasepool {
  210. [self lt_removeLogger:logger];
  211. } });
  212. }
  213. + (void)removeAllLoggers {
  214. [self.sharedInstance removeAllLoggers];
  215. }
  216. - (void)removeAllLoggers {
  217. dispatch_async(_loggingQueue, ^{ @autoreleasepool {
  218. [self lt_removeAllLoggers];
  219. } });
  220. }
  221. + (NSArray<id<OSSDDLogger>> *)allLoggers {
  222. return [self.sharedInstance allLoggers];
  223. }
  224. - (NSArray<id<OSSDDLogger>> *)allLoggers {
  225. __block NSArray *theLoggers;
  226. dispatch_sync(_loggingQueue, ^{ @autoreleasepool {
  227. theLoggers = [self lt_allLoggers];
  228. } });
  229. return theLoggers;
  230. }
  231. + (NSArray<OSSDDLoggerInformation *> *)allLoggersWithLevel {
  232. return [self.sharedInstance allLoggersWithLevel];
  233. }
  234. - (NSArray<OSSDDLoggerInformation *> *)allLoggersWithLevel {
  235. __block NSArray *theLoggersWithLevel;
  236. dispatch_sync(_loggingQueue, ^{ @autoreleasepool {
  237. theLoggersWithLevel = [self lt_allLoggersWithLevel];
  238. } });
  239. return theLoggersWithLevel;
  240. }
  241. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  242. #pragma mark - Master Logging
  243. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  244. - (void)queueLogMessage:(OSSDDLogMessage *)logMessage asynchronously:(BOOL)asyncFlag {
  245. // We have a tricky situation here...
  246. //
  247. // In the common case, when the queueSize is below the maximumQueueSize,
  248. // we want to simply enqueue the logMessage. And we want to do this as fast as possible,
  249. // which means we don't want to block and we don't want to use any locks.
  250. //
  251. // However, if the queueSize gets too big, we want to block.
  252. // But we have very strict requirements as to when we block, and how long we block.
  253. //
  254. // The following example should help illustrate our requirements:
  255. //
  256. // Imagine that the maximum queue size is configured to be 5,
  257. // and that there are already 5 log messages queued.
  258. // Let us call these 5 queued log messages A, B, C, D, and E. (A is next to be executed)
  259. //
  260. // Now if our thread issues a log statement (let us call the log message F),
  261. // it should block before the message is added to the queue.
  262. // Furthermore, it should be unblocked immediately after A has been unqueued.
  263. //
  264. // The requirements are strict in this manner so that we block only as long as necessary,
  265. // and so that blocked threads are unblocked in the order in which they were blocked.
  266. //
  267. // Returning to our previous example, let us assume that log messages A through E are still queued.
  268. // Our aforementioned thread is blocked attempting to queue log message F.
  269. // Now assume we have another separate thread that attempts to issue log message G.
  270. // It should block until log messages A and B have been unqueued.
  271. // We are using a counting semaphore provided by GCD.
  272. // The semaphore is initialized with our DDLOG_MAX_QUEUE_SIZE value.
  273. // Everytime we want to queue a log message we decrement this value.
  274. // If the resulting value is less than zero,
  275. // the semaphore function waits in FIFO order for a signal to occur before returning.
  276. //
  277. // A dispatch semaphore is an efficient implementation of a traditional counting semaphore.
  278. // Dispatch semaphores call down to the kernel only when the calling thread needs to be blocked.
  279. // If the calling semaphore does not need to block, no kernel call is made.
  280. dispatch_semaphore_wait(_queueSemaphore, DISPATCH_TIME_FOREVER);
  281. // We've now sure we won't overflow the queue.
  282. // It is time to queue our log message.
  283. dispatch_block_t logBlock = ^{
  284. @autoreleasepool {
  285. [self lt_log:logMessage];
  286. }
  287. };
  288. if (asyncFlag) {
  289. dispatch_async(_loggingQueue, logBlock);
  290. } else {
  291. dispatch_sync(_loggingQueue, logBlock);
  292. }
  293. }
  294. + (void)log:(BOOL)asynchronous
  295. level:(OSSDDLogLevel)level
  296. flag:(OSSDDLogFlag)flag
  297. context:(NSInteger)context
  298. file:(const char *)file
  299. function:(const char *)function
  300. line:(NSUInteger)line
  301. tag:(id)tag
  302. format:(NSString *)format, ... {
  303. va_list args;
  304. if (format) {
  305. va_start(args, format);
  306. NSString *message = [[NSString alloc] initWithFormat:format arguments:args];
  307. va_end(args);
  308. va_start(args, format);
  309. [self log:asynchronous
  310. message:message
  311. level:level
  312. flag:flag
  313. context:context
  314. file:file
  315. function:function
  316. line:line
  317. tag:tag];
  318. va_end(args);
  319. }
  320. }
  321. - (void)log:(BOOL)asynchronous
  322. level:(OSSDDLogLevel)level
  323. flag:(OSSDDLogFlag)flag
  324. context:(NSInteger)context
  325. file:(const char *)file
  326. function:(const char *)function
  327. line:(NSUInteger)line
  328. tag:(id)tag
  329. format:(NSString *)format, ... {
  330. va_list args;
  331. if (format) {
  332. va_start(args, format);
  333. NSString *message = [[NSString alloc] initWithFormat:format arguments:args];
  334. va_end(args);
  335. va_start(args, format);
  336. [self log:asynchronous
  337. message:message
  338. level:level
  339. flag:flag
  340. context:context
  341. file:file
  342. function:function
  343. line:line
  344. tag:tag];
  345. va_end(args);
  346. }
  347. }
  348. + (void)log:(BOOL)asynchronous
  349. level:(OSSDDLogLevel)level
  350. flag:(OSSDDLogFlag)flag
  351. context:(NSInteger)context
  352. file:(const char *)file
  353. function:(const char *)function
  354. line:(NSUInteger)line
  355. tag:(id)tag
  356. format:(NSString *)format
  357. args:(va_list)args {
  358. [self.sharedInstance log:asynchronous level:level flag:flag context:context file:file function:function line:line tag:tag format:format args:args];
  359. }
  360. - (void)log:(BOOL)asynchronous
  361. level:(OSSDDLogLevel)level
  362. flag:(OSSDDLogFlag)flag
  363. context:(NSInteger)context
  364. file:(const char *)file
  365. function:(const char *)function
  366. line:(NSUInteger)line
  367. tag:(id)tag
  368. format:(NSString *)format
  369. args:(va_list)args {
  370. if (format) {
  371. NSString *message = [[NSString alloc] initWithFormat:format arguments:args];
  372. [self log:asynchronous
  373. message:message
  374. level:level
  375. flag:flag
  376. context:context
  377. file:file
  378. function:function
  379. line:line
  380. tag:tag];
  381. }
  382. }
  383. + (void)log:(BOOL)asynchronous
  384. message:(NSString *)message
  385. level:(OSSDDLogLevel)level
  386. flag:(OSSDDLogFlag)flag
  387. context:(NSInteger)context
  388. file:(const char *)file
  389. function:(const char *)function
  390. line:(NSUInteger)line
  391. tag:(id)tag {
  392. [self.sharedInstance log:asynchronous message:message level:level flag:flag context:context file:file function:function line:line tag:tag];
  393. }
  394. - (void)log:(BOOL)asynchronous
  395. message:(NSString *)message
  396. level:(OSSDDLogLevel)level
  397. flag:(OSSDDLogFlag)flag
  398. context:(NSInteger)context
  399. file:(const char *)file
  400. function:(const char *)function
  401. line:(NSUInteger)line
  402. tag:(id)tag {
  403. OSSDDLogMessage *logMessage = [[OSSDDLogMessage alloc] initWithMessage:message
  404. level:level
  405. flag:flag
  406. context:context
  407. file:[NSString stringWithFormat:@"%s", file]
  408. function:[NSString stringWithFormat:@"%s", function]
  409. line:line
  410. tag:tag
  411. options:(OSSDDLogMessageOptions)0
  412. timestamp:nil];
  413. [self queueLogMessage:logMessage asynchronously:asynchronous];
  414. }
  415. + (void)log:(BOOL)asynchronous
  416. message:(OSSDDLogMessage *)logMessage {
  417. [self.sharedInstance log:asynchronous message:logMessage];
  418. }
  419. - (void)log:(BOOL)asynchronous
  420. message:(OSSDDLogMessage *)logMessage {
  421. [self queueLogMessage:logMessage asynchronously:asynchronous];
  422. }
  423. + (void)flushLog {
  424. [self.sharedInstance flushLog];
  425. }
  426. - (void)flushLog {
  427. dispatch_sync(_loggingQueue, ^{ @autoreleasepool {
  428. [self lt_flush];
  429. } });
  430. }
  431. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  432. #pragma mark Logging Thread
  433. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  434. - (void)lt_addLogger:(id <OSSDDLogger>)logger level:(OSSDDLogLevel)level {
  435. // Add to loggers array.
  436. // Need to create loggerQueue if loggerNode doesn't provide one.
  437. for (OSSLoggerNode* node in self._loggers) {
  438. if (node->_logger == logger
  439. && node->_level == level) {
  440. // Exactly same logger already added, exit
  441. return;
  442. }
  443. }
  444. NSAssert(dispatch_get_specific(GlobalLoggingQueueIdentityKey),
  445. @"This method should only be run on the logging thread/queue");
  446. dispatch_queue_t loggerQueue = NULL;
  447. if ([logger respondsToSelector:@selector(loggerQueue)]) {
  448. // Logger may be providing its own queue
  449. loggerQueue = [logger loggerQueue];
  450. }
  451. if (loggerQueue == nil) {
  452. // Automatically create queue for the logger.
  453. // Use the logger name as the queue name if possible.
  454. const char *loggerQueueName = NULL;
  455. if ([logger respondsToSelector:@selector(loggerName)]) {
  456. loggerQueueName = [[logger loggerName] UTF8String];
  457. }
  458. loggerQueue = dispatch_queue_create(loggerQueueName, NULL);
  459. }
  460. OSSLoggerNode *loggerNode = [OSSLoggerNode nodeWithLogger:logger loggerQueue:loggerQueue level:level];
  461. [self._loggers addObject:loggerNode];
  462. if ([logger respondsToSelector:@selector(didAddLoggerInQueue:)]) {
  463. dispatch_async(loggerNode->_loggerQueue, ^{ @autoreleasepool {
  464. [logger didAddLoggerInQueue:loggerNode->_loggerQueue];
  465. } });
  466. } else if ([logger respondsToSelector:@selector(didAddLogger)]) {
  467. dispatch_async(loggerNode->_loggerQueue, ^{ @autoreleasepool {
  468. [logger didAddLogger];
  469. } });
  470. }
  471. }
  472. - (void)lt_removeLogger:(id <OSSDDLogger>)logger {
  473. // Find associated loggerNode in list of added loggers
  474. NSAssert(dispatch_get_specific(GlobalLoggingQueueIdentityKey),
  475. @"This method should only be run on the logging thread/queue");
  476. OSSLoggerNode *loggerNode = nil;
  477. for (OSSLoggerNode *node in self._loggers) {
  478. if (node->_logger == logger) {
  479. loggerNode = node;
  480. break;
  481. }
  482. }
  483. if (loggerNode == nil) {
  484. OSSNSLogDebug(@"DDLog: Request to remove logger which wasn't added");
  485. return;
  486. }
  487. // Notify logger
  488. if ([logger respondsToSelector:@selector(willRemoveLogger)]) {
  489. dispatch_async(loggerNode->_loggerQueue, ^{ @autoreleasepool {
  490. [logger willRemoveLogger];
  491. } });
  492. }
  493. // Remove from loggers array
  494. [self._loggers removeObject:loggerNode];
  495. }
  496. - (void)lt_removeAllLoggers {
  497. NSAssert(dispatch_get_specific(GlobalLoggingQueueIdentityKey),
  498. @"This method should only be run on the logging thread/queue");
  499. // Notify all loggers
  500. for (OSSLoggerNode *loggerNode in self._loggers) {
  501. if ([loggerNode->_logger respondsToSelector:@selector(willRemoveLogger)]) {
  502. dispatch_async(loggerNode->_loggerQueue, ^{ @autoreleasepool {
  503. [loggerNode->_logger willRemoveLogger];
  504. } });
  505. }
  506. }
  507. // Remove all loggers from array
  508. [self._loggers removeAllObjects];
  509. }
  510. - (NSArray *)lt_allLoggers {
  511. NSAssert(dispatch_get_specific(GlobalLoggingQueueIdentityKey),
  512. @"This method should only be run on the logging thread/queue");
  513. NSMutableArray *theLoggers = [NSMutableArray new];
  514. for (OSSLoggerNode *loggerNode in self._loggers) {
  515. [theLoggers addObject:loggerNode->_logger];
  516. }
  517. return [theLoggers copy];
  518. }
  519. - (NSArray *)lt_allLoggersWithLevel {
  520. NSAssert(dispatch_get_specific(GlobalLoggingQueueIdentityKey),
  521. @"This method should only be run on the logging thread/queue");
  522. NSMutableArray *theLoggersWithLevel = [NSMutableArray new];
  523. for (OSSLoggerNode *loggerNode in self._loggers) {
  524. [theLoggersWithLevel addObject:[OSSDDLoggerInformation informationWithLogger:loggerNode->_logger
  525. andLevel:loggerNode->_level]];
  526. }
  527. return [theLoggersWithLevel copy];
  528. }
  529. - (void)lt_log:(OSSDDLogMessage *)logMessage {
  530. // Execute the given log message on each of our loggers.
  531. NSAssert(dispatch_get_specific(GlobalLoggingQueueIdentityKey),
  532. @"This method should only be run on the logging thread/queue");
  533. if (_numProcessors > 1) {
  534. // Execute each logger concurrently, each within its own queue.
  535. // All blocks are added to same group.
  536. // After each block has been queued, wait on group.
  537. //
  538. // The waiting ensures that a slow logger doesn't end up with a large queue of pending log messages.
  539. // This would defeat the purpose of the efforts we made earlier to restrict the max queue size.
  540. for (OSSLoggerNode *loggerNode in self._loggers) {
  541. // skip the loggers that shouldn't write this message based on the log level
  542. if (!(logMessage->_flag & loggerNode->_level)) {
  543. continue;
  544. }
  545. dispatch_group_async(_loggingGroup, loggerNode->_loggerQueue, ^{ @autoreleasepool {
  546. [loggerNode->_logger logMessage:logMessage];
  547. } });
  548. }
  549. dispatch_group_wait(_loggingGroup, DISPATCH_TIME_FOREVER);
  550. } else {
  551. // Execute each logger serialy, each within its own queue.
  552. for (OSSLoggerNode *loggerNode in self._loggers) {
  553. // skip the loggers that shouldn't write this message based on the log level
  554. if (!(logMessage->_flag & loggerNode->_level)) {
  555. continue;
  556. }
  557. dispatch_sync(loggerNode->_loggerQueue, ^{ @autoreleasepool {
  558. [loggerNode->_logger logMessage:logMessage];
  559. } });
  560. }
  561. }
  562. // If our queue got too big, there may be blocked threads waiting to add log messages to the queue.
  563. // Since we've now dequeued an item from the log, we may need to unblock the next thread.
  564. // We are using a counting semaphore provided by GCD.
  565. // The semaphore is initialized with our DDLOG_MAX_QUEUE_SIZE value.
  566. // When a log message is queued this value is decremented.
  567. // When a log message is dequeued this value is incremented.
  568. // If the value ever drops below zero,
  569. // the queueing thread blocks and waits in FIFO order for us to signal it.
  570. //
  571. // A dispatch semaphore is an efficient implementation of a traditional counting semaphore.
  572. // Dispatch semaphores call down to the kernel only when the calling thread needs to be blocked.
  573. // If the calling semaphore does not need to block, no kernel call is made.
  574. dispatch_semaphore_signal(_queueSemaphore);
  575. }
  576. - (void)lt_flush {
  577. // All log statements issued before the flush method was invoked have now been executed.
  578. //
  579. // Now we need to propogate the flush request to any loggers that implement the flush method.
  580. // This is designed for loggers that buffer IO.
  581. NSAssert(dispatch_get_specific(GlobalLoggingQueueIdentityKey),
  582. @"This method should only be run on the logging thread/queue");
  583. for (OSSLoggerNode *loggerNode in self._loggers) {
  584. if ([loggerNode->_logger respondsToSelector:@selector(flush)]) {
  585. dispatch_group_async(_loggingGroup, loggerNode->_loggerQueue, ^{ @autoreleasepool {
  586. [loggerNode->_logger flush];
  587. } });
  588. }
  589. }
  590. dispatch_group_wait(_loggingGroup, DISPATCH_TIME_FOREVER);
  591. }
  592. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  593. #pragma mark Utilities
  594. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  595. NSString * __nullable OSSDDExtractFileNameWithoutExtension(const char *filePath, BOOL copy) {
  596. if (filePath == NULL) {
  597. return nil;
  598. }
  599. char *lastSlash = NULL;
  600. char *lastDot = NULL;
  601. char *p = (char *)filePath;
  602. while (*p != '\0') {
  603. if (*p == '/') {
  604. lastSlash = p;
  605. } else if (*p == '.') {
  606. lastDot = p;
  607. }
  608. p++;
  609. }
  610. char *subStr;
  611. NSUInteger subLen;
  612. if (lastSlash) {
  613. if (lastDot) {
  614. // lastSlash -> lastDot
  615. subStr = lastSlash + 1;
  616. subLen = (NSUInteger)(lastDot - subStr);
  617. } else {
  618. // lastSlash -> endOfString
  619. subStr = lastSlash + 1;
  620. subLen = (NSUInteger)(p - subStr);
  621. }
  622. } else {
  623. if (lastDot) {
  624. // startOfString -> lastDot
  625. subStr = (char *)filePath;
  626. subLen = (NSUInteger)(lastDot - subStr);
  627. } else {
  628. // startOfString -> endOfString
  629. subStr = (char *)filePath;
  630. subLen = (NSUInteger)(p - subStr);
  631. }
  632. }
  633. if (copy) {
  634. return [[NSString alloc] initWithBytes:subStr
  635. length:subLen
  636. encoding:NSUTF8StringEncoding];
  637. } else {
  638. // We can take advantage of the fact that __FILE__ is a string literal.
  639. // Specifically, we don't need to waste time copying the string.
  640. // We can just tell NSString to point to a range within the string literal.
  641. return [[NSString alloc] initWithBytesNoCopy:subStr
  642. length:subLen
  643. encoding:NSUTF8StringEncoding
  644. freeWhenDone:NO];
  645. }
  646. }
  647. @end
  648. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  649. #pragma mark -
  650. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  651. @implementation OSSLoggerNode
  652. - (instancetype)initWithLogger:(id <OSSDDLogger>)logger loggerQueue:(dispatch_queue_t)loggerQueue level:(OSSDDLogLevel)level {
  653. if ((self = [super init])) {
  654. _logger = logger;
  655. if (loggerQueue) {
  656. _loggerQueue = loggerQueue;
  657. #if !OS_OBJECT_USE_OBJC
  658. dispatch_retain(loggerQueue);
  659. #endif
  660. }
  661. _level = level;
  662. }
  663. return self;
  664. }
  665. + (OSSLoggerNode *)nodeWithLogger:(id <OSSDDLogger>)logger loggerQueue:(dispatch_queue_t)loggerQueue level:(OSSDDLogLevel)level {
  666. return [[OSSLoggerNode alloc] initWithLogger:logger loggerQueue:loggerQueue level:level];
  667. }
  668. - (void)dealloc {
  669. #if !OS_OBJECT_USE_OBJC
  670. if (_loggerQueue) {
  671. dispatch_release(_loggerQueue);
  672. }
  673. #endif
  674. }
  675. @end
  676. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  677. #pragma mark -
  678. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  679. @implementation OSSDDLogMessage
  680. // Can we use DISPATCH_CURRENT_QUEUE_LABEL ?
  681. // Can we use dispatch_get_current_queue (without it crashing) ?
  682. //
  683. // a) Compiling against newer SDK's (iOS 7+/OS X 10.9+) where DISPATCH_CURRENT_QUEUE_LABEL is defined
  684. // on a (iOS 7.0+/OS X 10.9+) runtime version
  685. //
  686. // b) Systems where dispatch_get_current_queue is not yet deprecated and won't crash (< iOS 6.0/OS X 10.9)
  687. //
  688. // dispatch_get_current_queue(void);
  689. // __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_6,__MAC_10_9,__IPHONE_4_0,__IPHONE_6_0)
  690. #if TARGET_OS_IOS
  691. // Compiling for iOS
  692. static BOOL _use_dispatch_current_queue_label;
  693. static BOOL _use_dispatch_get_current_queue;
  694. static void _dispatch_queue_label_init_once(void * __attribute__((unused)) context)
  695. {
  696. _use_dispatch_current_queue_label = (UIDevice.currentDevice.systemVersion.floatValue >= 7.0f);
  697. _use_dispatch_get_current_queue = (!_use_dispatch_current_queue_label && UIDevice.currentDevice.systemVersion.floatValue >= 6.1f);
  698. }
  699. static __inline__ __attribute__((__always_inline__)) void _dispatch_queue_label_init()
  700. {
  701. static dispatch_once_t onceToken;
  702. dispatch_once_f(&onceToken, NULL, _dispatch_queue_label_init_once);
  703. }
  704. #define USE_DISPATCH_CURRENT_QUEUE_LABEL (_dispatch_queue_label_init(), _use_dispatch_current_queue_label)
  705. #define USE_DISPATCH_GET_CURRENT_QUEUE (_dispatch_queue_label_init(), _use_dispatch_get_current_queue)
  706. #elif TARGET_OS_WATCH || TARGET_OS_TV
  707. // Compiling for watchOS, tvOS
  708. #define USE_DISPATCH_CURRENT_QUEUE_LABEL YES
  709. #define USE_DISPATCH_GET_CURRENT_QUEUE NO
  710. #else
  711. // Compiling for Mac OS X
  712. #ifndef MAC_OS_X_VERSION_10_9
  713. #define MAC_OS_X_VERSION_10_9 1090
  714. #endif
  715. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9 // Mac OS X 10.9 or later required
  716. #define USE_DISPATCH_CURRENT_QUEUE_LABEL YES
  717. #define USE_DISPATCH_GET_CURRENT_QUEUE NO
  718. #else
  719. static BOOL _use_dispatch_current_queue_label;
  720. static BOOL _use_dispatch_get_current_queue;
  721. static void _dispatch_queue_label_init_once(void * __attribute__((unused)) context)
  722. {
  723. _use_dispatch_current_queue_label = [NSTimer instancesRespondToSelector : @selector(tolerance)]; // OS X 10.9+
  724. _use_dispatch_get_current_queue = !_use_dispatch_current_queue_label; // < OS X 10.9
  725. }
  726. static __inline__ __attribute__((__always_inline__)) void _dispatch_queue_label_init()
  727. {
  728. static dispatch_once_t onceToken;
  729. dispatch_once_f(&onceToken, NULL, _dispatch_queue_label_init_once);
  730. }
  731. #define USE_DISPATCH_CURRENT_QUEUE_LABEL (_dispatch_queue_label_init(), _use_dispatch_current_queue_label)
  732. #define USE_DISPATCH_GET_CURRENT_QUEUE (_dispatch_queue_label_init(), _use_dispatch_get_current_queue)
  733. #endif
  734. #endif /* if TARGET_OS_IOS */
  735. // Should we use pthread_threadid_np ?
  736. // With iOS 8+/OSX 10.10+ NSLog uses pthread_threadid_np instead of pthread_mach_thread_np
  737. #if TARGET_OS_IOS
  738. // Compiling for iOS
  739. #ifndef kCFCoreFoundationVersionNumber_iOS_8_0
  740. #define kCFCoreFoundationVersionNumber_iOS_8_0 1140.10
  741. #endif
  742. #define USE_PTHREAD_THREADID_NP (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_8_0)
  743. #elif TARGET_OS_WATCH || TARGET_OS_TV
  744. // Compiling for watchOS, tvOS
  745. #define USE_PTHREAD_THREADID_NP YES
  746. #else
  747. // Compiling for Mac OS X
  748. #ifndef kCFCoreFoundationVersionNumber10_10
  749. #define kCFCoreFoundationVersionNumber10_10 1151.16
  750. #endif
  751. #define USE_PTHREAD_THREADID_NP (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_10)
  752. #endif /* if TARGET_OS_IOS */
  753. - (instancetype)init {
  754. self = [super init];
  755. return self;
  756. }
  757. - (instancetype)initWithMessage:(NSString *)message
  758. level:(OSSDDLogLevel)level
  759. flag:(OSSDDLogFlag)flag
  760. context:(NSInteger)context
  761. file:(NSString *)file
  762. function:(NSString *)function
  763. line:(NSUInteger)line
  764. tag:(id)tag
  765. options:(OSSDDLogMessageOptions)options
  766. timestamp:(NSDate *)timestamp {
  767. if ((self = [super init])) {
  768. BOOL copyMessage = (options & OSSDDLogMessageDontCopyMessage) == 0;
  769. _message = copyMessage ? [message copy] : message;
  770. _level = level;
  771. _flag = flag;
  772. _context = context;
  773. BOOL copyFile = (options & OSSDDLogMessageCopyFile) != 0;
  774. _file = copyFile ? [file copy] : file;
  775. BOOL copyFunction = (options & OSSDDLogMessageCopyFunction) != 0;
  776. _function = copyFunction ? [function copy] : function;
  777. _line = line;
  778. _tag = tag;
  779. _options = options;
  780. _timestamp = timestamp ?: [NSDate new];
  781. if (USE_PTHREAD_THREADID_NP) {
  782. __uint64_t tid;
  783. pthread_threadid_np(NULL, &tid);
  784. _threadID = [[NSString alloc] initWithFormat:@"%llu", tid];
  785. } else {
  786. _threadID = [[NSString alloc] initWithFormat:@"%x", pthread_mach_thread_np(pthread_self())];
  787. }
  788. _threadName = NSThread.currentThread.name;
  789. // Get the file name without extension
  790. _fileName = [_file lastPathComponent];
  791. NSUInteger dotLocation = [_fileName rangeOfString:@"." options:NSBackwardsSearch].location;
  792. if (dotLocation != NSNotFound)
  793. {
  794. _fileName = [_fileName substringToIndex:dotLocation];
  795. }
  796. // Try to get the current queue's label
  797. if (USE_DISPATCH_CURRENT_QUEUE_LABEL) {
  798. _queueLabel = [[NSString alloc] initWithFormat:@"%s", dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)];
  799. } else if (USE_DISPATCH_GET_CURRENT_QUEUE) {
  800. #pragma clang diagnostic push
  801. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  802. dispatch_queue_t currentQueue = dispatch_get_current_queue();
  803. #pragma clang diagnostic pop
  804. _queueLabel = [[NSString alloc] initWithFormat:@"%s", dispatch_queue_get_label(currentQueue)];
  805. } else {
  806. _queueLabel = @""; // iOS 6.x only
  807. }
  808. }
  809. return self;
  810. }
  811. - (id)copyWithZone:(NSZone * __attribute__((unused)))zone {
  812. OSSDDLogMessage *newMessage = [OSSDDLogMessage new];
  813. newMessage->_message = _message;
  814. newMessage->_level = _level;
  815. newMessage->_flag = _flag;
  816. newMessage->_context = _context;
  817. newMessage->_file = _file;
  818. newMessage->_fileName = _fileName;
  819. newMessage->_function = _function;
  820. newMessage->_line = _line;
  821. newMessage->_tag = _tag;
  822. newMessage->_options = _options;
  823. newMessage->_timestamp = _timestamp;
  824. newMessage->_threadID = _threadID;
  825. newMessage->_threadName = _threadName;
  826. newMessage->_queueLabel = _queueLabel;
  827. return newMessage;
  828. }
  829. @end
  830. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  831. #pragma mark -
  832. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  833. @implementation OSSDDAbstractLogger
  834. - (instancetype)init {
  835. if ((self = [super init])) {
  836. const char *loggerQueueName = NULL;
  837. if ([self respondsToSelector:@selector(loggerName)]) {
  838. loggerQueueName = [[self loggerName] UTF8String];
  839. }
  840. _loggerQueue = dispatch_queue_create(loggerQueueName, NULL);
  841. // We're going to use dispatch_queue_set_specific() to "mark" our loggerQueue.
  842. // Later we can use dispatch_get_specific() to determine if we're executing on our loggerQueue.
  843. // The documentation states:
  844. //
  845. // > Keys are only compared as pointers and are never dereferenced.
  846. // > Thus, you can use a pointer to a static variable for a specific subsystem or
  847. // > any other value that allows you to identify the value uniquely.
  848. // > Specifying a pointer to a string constant is not recommended.
  849. //
  850. // So we're going to use the very convenient key of "self",
  851. // which also works when multiple logger classes extend this class, as each will have a different "self" key.
  852. //
  853. // This is used primarily for thread-safety assertions (via the isOnInternalLoggerQueue method below).
  854. void *key = (__bridge void *)self;
  855. void *nonNullValue = (__bridge void *)self;
  856. dispatch_queue_set_specific(_loggerQueue, key, nonNullValue, NULL);
  857. }
  858. return self;
  859. }
  860. - (void)dealloc {
  861. #if !OS_OBJECT_USE_OBJC
  862. if (_loggerQueue) {
  863. dispatch_release(_loggerQueue);
  864. }
  865. #endif
  866. }
  867. - (void)logMessage:(OSSDDLogMessage * __attribute__((unused)))logMessage {
  868. // Override me
  869. }
  870. - (id <OSSDDLogFormatter>)logFormatter {
  871. // This method must be thread safe and intuitive.
  872. // Therefore if somebody executes the following code:
  873. //
  874. // [logger setLogFormatter:myFormatter];
  875. // formatter = [logger logFormatter];
  876. //
  877. // They would expect formatter to equal myFormatter.
  878. // This functionality must be ensured by the getter and setter method.
  879. //
  880. // The thread safety must not come at a cost to the performance of the logMessage method.
  881. // This method is likely called sporadically, while the logMessage method is called repeatedly.
  882. // This means, the implementation of this method:
  883. // - Must NOT require the logMessage method to acquire a lock.
  884. // - Must NOT require the logMessage method to access an atomic property (also a lock of sorts).
  885. //
  886. // Thread safety is ensured by executing access to the formatter variable on the loggerQueue.
  887. // This is the same queue that the logMessage method operates on.
  888. //
  889. // Note: The last time I benchmarked the performance of direct access vs atomic property access,
  890. // direct access was over twice as fast on the desktop and over 6 times as fast on the iPhone.
  891. //
  892. // Furthermore, consider the following code:
  893. //
  894. // DDLogVerbose(@"log msg 1");
  895. // DDLogVerbose(@"log msg 2");
  896. // [logger setFormatter:myFormatter];
  897. // DDLogVerbose(@"log msg 3");
  898. //
  899. // Our intuitive requirement means that the new formatter will only apply to the 3rd log message.
  900. // This must remain true even when using asynchronous logging.
  901. // We must keep in mind the various queue's that are in play here:
  902. //
  903. // loggerQueue : Our own private internal queue that the logMessage method runs on.
  904. // Operations are added to this queue from the global loggingQueue.
  905. //
  906. // globalLoggingQueue : The queue that all log messages go through before they arrive in our loggerQueue.
  907. //
  908. // All log statements go through the serial gloabalLoggingQueue before they arrive at our loggerQueue.
  909. // Thus this method also goes through the serial globalLoggingQueue to ensure intuitive operation.
  910. // IMPORTANT NOTE:
  911. //
  912. // Methods within the DDLogger implementation MUST access the formatter ivar directly.
  913. // This method is designed explicitly for external access.
  914. //
  915. // Using "self." syntax to go through this method will cause immediate deadlock.
  916. // This is the intended result. Fix it by accessing the ivar directly.
  917. // Great strides have been take to ensure this is safe to do. Plus it's MUCH faster.
  918. NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
  919. NSAssert(![self isOnInternalLoggerQueue], @"MUST access ivar directly, NOT via self.* syntax.");
  920. dispatch_queue_t globalLoggingQueue = [OSSDDLog loggingQueue];
  921. __block id <OSSDDLogFormatter> result;
  922. dispatch_sync(globalLoggingQueue, ^{
  923. dispatch_sync(_loggerQueue, ^{
  924. result = _logFormatter;
  925. });
  926. });
  927. return result;
  928. }
  929. - (void)setLogFormatter:(id <OSSDDLogFormatter>)logFormatter {
  930. // The design of this method is documented extensively in the logFormatter message (above in code).
  931. NSAssert(![self isOnGlobalLoggingQueue], @"Core architecture requirement failure");
  932. NSAssert(![self isOnInternalLoggerQueue], @"MUST access ivar directly, NOT via self.* syntax.");
  933. dispatch_block_t block = ^{
  934. @autoreleasepool {
  935. if (_logFormatter != logFormatter) {
  936. if ([_logFormatter respondsToSelector:@selector(willRemoveFromLogger:)]) {
  937. [_logFormatter willRemoveFromLogger:self];
  938. }
  939. _logFormatter = logFormatter;
  940. if ([_logFormatter respondsToSelector:@selector(didAddToLogger:inQueue:)]) {
  941. [_logFormatter didAddToLogger:self inQueue:_loggerQueue];
  942. } else if ([_logFormatter respondsToSelector:@selector(didAddToLogger:)]) {
  943. [_logFormatter didAddToLogger:self];
  944. }
  945. }
  946. }
  947. };
  948. dispatch_queue_t globalLoggingQueue = [OSSDDLog loggingQueue];
  949. dispatch_async(globalLoggingQueue, ^{
  950. dispatch_async(_loggerQueue, block);
  951. });
  952. }
  953. - (dispatch_queue_t)loggerQueue {
  954. return _loggerQueue;
  955. }
  956. - (NSString *)loggerName {
  957. return NSStringFromClass([self class]);
  958. }
  959. - (BOOL)isOnGlobalLoggingQueue {
  960. return (dispatch_get_specific(GlobalLoggingQueueIdentityKey) != NULL);
  961. }
  962. - (BOOL)isOnInternalLoggerQueue {
  963. void *key = (__bridge void *)self;
  964. return (dispatch_get_specific(key) != NULL);
  965. }
  966. @end
  967. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  968. #pragma mark -
  969. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  970. @interface OSSDDLoggerInformation()
  971. {
  972. // Direct accessors to be used only for performance
  973. @public
  974. id <OSSDDLogger> _logger;
  975. OSSDDLogLevel _level;
  976. }
  977. @end
  978. @implementation OSSDDLoggerInformation
  979. - (instancetype)initWithLogger:(id <OSSDDLogger>)logger andLevel:(OSSDDLogLevel)level {
  980. if ((self = [super init])) {
  981. _logger = logger;
  982. _level = level;
  983. }
  984. return self;
  985. }
  986. + (OSSDDLoggerInformation *)informationWithLogger:(id <OSSDDLogger>)logger andLevel:(OSSDDLogLevel)level {
  987. return [[OSSDDLoggerInformation alloc] initWithLogger:logger andLevel:level];
  988. }
  989. @end