You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey,
i am using Spring Boot and logback.
I try to use Loki appender using runtime credentials provided via environment variables.
I saw that logback.xml supports substitution of environment variables, but this is not really nice if one chains url parameters.
I tried to create the log appender via code but its not sending logs to the endpoint.
This is my code to create the Appender:
private Loki4jAppender getLoki4jAppender(final LoggerContext loggerContext) {
final AbstractHttpSender.BasicAuth basicAuth = new AbstractHttpSender.BasicAuth();
basicAuth.setPassword(environment.getArgusPassword());
basicAuth.setUsername(environment.getArgusUser());
final JavaHttpSender javaHttpSender = new JavaHttpSender();
javaHttpSender.setUrl(environment.getArgusLogUrl());
javaHttpSender.setAuth(basicAuth);
final Loki4jEncoder loki4jEncoder = new JsonEncoder();
final Loki4jAppender appender = new Loki4jAppender();
appender.setHttp(javaHttpSender);
appender.setContext(loggerContext);
appender.setBatchMaxItems(1);
appender.setFormat(loki4jEncoder);
appender.setDrainOnStop(true);
appender.setVerbose(true);
return appender;
}
Currently i try to add it to all available loggers:
final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
final Loki4jAppender appender = getLoki4jAppender(loggerContext);
for(Logger logger : loggerContext.getLoggerList()) {
log.debug("Adding loki appender to the logger '{}'", logger.getName());
logger.addAppender(appender);
}
This discussion was converted from issue #241 on June 24, 2024 07:03.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey,
i am using Spring Boot and logback.
I try to use Loki appender using runtime credentials provided via environment variables.
I saw that logback.xml supports substitution of environment variables, but this is not really nice if one chains url parameters.
I tried to create the log appender via code but its not sending logs to the endpoint.
This is my code to create the Appender:
Currently i try to add it to all available loggers:
I use the following dependencies:
Thanks for Your Help
Clem
Beta Was this translation helpful? Give feedback.
All reactions