From 086003eb7d403a1a767cc8164538eca7d1694864 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Tue, 16 Sep 2014 18:57:07 +0000 Subject: [PATCH] clear cached logger objects when necessary git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@38086 72102866-910b-0410-8b05-ffd578937521 --- EcLogger.h | 4 ++++ EcLogger.m | 19 ++++++++++++++++++- EcProcess.m | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/EcLogger.h b/EcLogger.h index 2b63a07..5382c0e 100644 --- a/EcLogger.h +++ b/EcLogger.h @@ -112,5 +112,9 @@ @end +/** Notification sent when the logging set of cached loggers is emptied. + */ +extern NSString* const EcLoggersDidChangeNotification; + #endif diff --git a/EcLogger.m b/EcLogger.m index cf6d350..f05fae7 100644 --- a/EcLogger.m +++ b/EcLogger.m @@ -33,6 +33,9 @@ #import "EcProcess.h" #import "EcLogger.h" +NSString* const EcLoggersDidChangeNotification + = @"EcLoggersDidChangeNotification"; + @implementation EcLogger static Class loggersClass; @@ -100,11 +103,25 @@ static NSArray *modes; + (void) setFactory: (Class)c { + NSMutableArray *old = nil; + if (Nil == c) c = [self class]; NSAssert([c isSubclassOfClass: self], NSInvalidArgumentException); [loggersLock lock]; - loggersClass = c; + if (loggersClass != c) + { + old = loggers; + loggers = [NSMutableArray new]; + loggersClass = c; + } [loggersLock unlock]; + if (nil != old) + { + [old makeObjectsPerformSelector: @selector(flush)]; + [old release]; + [[NSNotificationCenter defaultCenter] postNotificationName: + EcLoggersDidChangeNotification object: self]; + } } /* Should only be called on main thread, but doesn't matter. diff --git a/EcProcess.m b/EcProcess.m index d47bb98..76e58f2 100644 --- a/EcProcess.m +++ b/EcProcess.m @@ -1495,6 +1495,15 @@ static NSString *noFiles = @"No log files to archive"; return cmdSignalled; } +- (void) ecLoggersChanged: (NSNotification*)n +{ + DESTROY(alertLogger); + DESTROY(auditLogger); + DESTROY(debugLogger); + DESTROY(errorLogger); + DESTROY(warningLogger); +} + - (NSDate*) ecStarted { return started; @@ -3814,6 +3823,12 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval); name: NSUserDefaultsDidChangeNotification object: [NSUserDefaults standardUserDefaults]]; + [[NSNotificationCenter defaultCenter] + addObserver: self + selector: @selector(ecLoggersChanged:) + name: EcLoggersDidChangeNotification + object: nil]; + [self cmdMesgCache]; [self cmdDefaultsChanged: nil];