fluent/fluent-logger-java

Calling `.close()` does not clean up instance in `FluentLoggerFactory`

tjratch opened this issue · 2 comments

fluentLogger = FluentLogger.getLogger("tagprefix", "myhost", 24224)
fluentLogger.close();
fluentLogger = FluentLogger.getLogger("tagprefix", "myhost", 24224)
fluentLogger.log('mytag', 'my message'); // wont work

If you close an individual Fluentlogger the instance retained in the FluentLoggerFactory persists, but the Sender will be null and cannot send out messages.

You can call FluentLogger.closeAll() to fix the above, but this is too aggressive because it will close all loggers which may not be your intention.

Ideally there would be a FluentLogger.close(myFluentLogger) method which would clean up the logger in the FluentLoggerFactory

Actually, upon further inspection you need to remove all references because the fluentAppender is stored in a WeakHashMap, but this is optimistic and relies on garbage collection, which is not guaranteed.

In other words, to avoid having the FluentLogger in the FluentLoggerFactory you will have to remove all references to the instance and even call System.gc() to make sure it drops out of the WeakHashMap, but again, this optimistic

Duplicate of #64