fluent-logger-java icon indicating copy to clipboard operation
fluent-logger-java copied to clipboard

Conflict with Spring cloud SpringApplication run

Open hmc1986 opened this issue 6 years ago • 0 comments

Conflict with Spring cloud SpringApplication run. spring cloud because BootstrapApplicationListener.Causes Spring Application to execute many times. and call FluentLogger stop. close sender, with sender is null. then call log(String tag, Map<String, Object> data, long timestamp) function Throw out NullPointerException? in FluentLoggerFactory 58 line add this code?

public synchronized FluentLogger getLogger(String tagPrefix, String host, int port, int timeout, int bufferCapacity,
            Reconnector reconnector) {
        String key = String.format("%s_%s_%d_%d_%d", new Object[] { tagPrefix, host, port, timeout, bufferCapacity });

        for (Map.Entry<FluentLogger, String> entry : loggers.entrySet()) {
            if (entry.getValue().equals(key)) {
                FluentLogger found = entry.getKey();
                if(found != null) {
                    if(found.getSender() == null){
                        found.setSender(getNewSender(host, port, timeout, bufferCapacity, reconnector));
                    }
                    return found;
                }
                break;
            }
        }


        FluentLogger logger = new FluentLogger(tagPrefix, getNewSender(host, port, timeout, bufferCapacity, reconnector));
        loggers.put(logger, key);
        return logger;
    }

private Sender getNewSender( String host, int port, int timeout, int bufferCapacity, Reconnector reconnector){
        Sender sender = null;
        Properties props = System.getProperties();
        if (!props.containsKey(Config.FLUENT_SENDER_CLASS)) {
            // create default sender object
            sender = new RawSocketSender(host, port, timeout, bufferCapacity, reconnector);
        } else {
            String senderClassName = props.getProperty(Config.FLUENT_SENDER_CLASS);
            try {
                sender = createSenderInstance(senderClassName, new Object[] { host, port, timeout, bufferCapacity });
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return sender;
    }

hmc1986 avatar Mar 08 '19 02:03 hmc1986