version 0.3.2 cause null sender from FluentLoggerFactory.getLogger
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- java, spring-boot
- Domaine
- backend
Piste de recherche
Commencez par FluentLoggerFactory.getLogger et FluentLogger.close, puis reproduisez la configuration Spring Boot/logback décrite dans l’issue. Suivez le comportement de l’entrée de WeakHashMap et du null sender après que le sender ne peut pas se connecter ou que FluentLogger.close() est exécuté. Le travail est terminé lorsque le logger obtenu après le démarrage de l’application se comporte correctement au lieu de conserver un null sender.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
I have read some issues before about the reason to use a WeakHashMap in FluentLoggerFactory. And the WeakHashMap was changed from WeakHashMap<String, FluentLogger> (version 0.3.1) to WeakHashMap<FluentLogger, String>(current version 0.3.2).
But I got a FluentLogger with null sender in version 0.3.2 when using logback in Spring Boot application.
The sender could not be connecting to fluent server for long time. So the sender should be assigned to null after calling FluentLogger.close().
But in my situation, how can I get a work-well logger after Spring Boot application has been luanched.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
public class FluentLoggerFactory {
private final Map<FluentLogger, String> loggers;
public FluentLoggerFactory() {
loggers = new WeakHashMap<FluentLogger, String>();
}
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) {
return found; // the found contains a null valued sender
}
break;
}
}
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);
}
}
FluentLogger logger = new FluentLogger(tagPrefix, sender);
loggers.put(logger, key);
return logger;
}
...
...
}
@SpringBootApplication
public class Application {
private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
LOGGER.info("hello world);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProperty scope="context" name="springAppName" source="spring.application.name"/>
<property name="CONSOLE_LOG_PATTERN"
value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr([${springAppName:-},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-B3-ParentSpanId:-},%X{X-Span-Export:-}]){yellow} %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<appender name="FLUENT_TEXT_SYNC" class="ch.qos.logback.more.appenders.FluentLogbackAppender">
<tag>debug</tag>
<label>logback</label>
<remoteHost>localhost</remoteHost>
<port>24224</port>
</appender>
<appender name="FLUENT_TEXT" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>999</queueSize>
<appender-ref ref="FLUENT_TEXT_SYNC" />
</appender>
<logger name="org.springframework" level="INFO"/>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FLUENT_TEXT"/>
</root>
</configuration>
public class FluentLogger {
public boolean log(String tag, Map<String, Object> data, long timestamp) {
String concatTag = null;
if (tagPrefix == null || tagPrefix.length() == 0) {
concatTag = tag;
}
else {
concatTag = tagPrefix + "." + tag;
}
if (timestamp != 0) {
return sender.emit(concatTag, timestamp, data);
} else {
return sender.emit(concatTag, data);
}
}
public void flush() {
sender.flush();
}
public void close() {
if (sender != null) {
sender.flush();
sender.close();
sender = null; // set sender to null after closing FluentLogger
}
}
}
- Langage dominant
- Java
- Étoiles
- 210
- Forks
- 86
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de fluent/fluent-logger-java
-
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
fluent/fluent-logger-java#100 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 15/100
fluent/fluent-logger-java#99 · 1 commentaire · 2 réactions ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
fluent/fluent-logger-java#98 · 1 commentaire ·
-
Null Pointer Exception with slf4j-log4j12-1.7.30 (Fluent-logger incompatible with the new version)Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 42/100
fluent/fluent-logger-java#89 · 3 commentaires ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 25/100
fluent/fluent-logger-java#88 · 1 commentaire ·
Toutes les issues de fluent/fluent-logger-java
Issues similaires
-
`timer` rule rejects dates the engine acceptsPeut-être pris @MFA-G l’a pris aujourd’hui. Ouvertebug ready
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
camunda/bpmnlint-plugin-camunda-compat#281 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
status: waiting-for-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Les mainteneurs répondent en général sous 1 jour
-
AOT compilation fails for derived delete queries returning SetPeut-être pris @ryujungkyun l’a pris aujourd’hui. Ouvertestatus: waiting-for-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
spring-projects/spring-data-jpa#4387 ·
Les mainteneurs répondent en général sous 3 jours