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
This commit is contained in:
Richard Frith-MacDonald 2014-09-16 18:57:07 +00:00
parent b6f56ee478
commit 086003eb7d
3 changed files with 37 additions and 1 deletions

View file

@ -112,5 +112,9 @@
@end
/** Notification sent when the logging set of cached loggers is emptied.
*/
extern NSString* const EcLoggersDidChangeNotification;
#endif

View file

@ -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];
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.

View file

@ -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];