Comments (2)
Yes this will have to be implemented. But that would be a good addition
from quarkus-logging-manager.
I created a custom implementation for this. We had at my job a implementation using SpringBoot and I had to do the same thing for quarkus.
I did a HACK. I didn't modify any of quarkus-logging-manager instead a use a RestClient to call logging-manager endpoint from within my application.
I also create a new controller that will handle to logic.
@Slf4j
@Path("/api/v1/loggers")
@Produces(MediaType.APPLICATION_JSON)
public class LoggingController {
@Inject
@RestClient
LoggingServiceRestConnector loggingServiceRestConnector;
@Inject
ObjectMapper mapper;
JsonPersistence persistenceOriginal;
@PostConstruct
void init() throws Exception {
// save original logger levels on disk
persistence.save(getAvailableLoggers(), "original.json");
// load overriden loggers
applyPersistedLogLevels();
}
private void applyPersistedLogLevels() throws Exception {
log.debug("Loading persisted log levels....");
persistence.findAll()
.forEach(loggerSetting -> loggingServiceRestConnector.updateLogger(loggerSetting.getLoggerName(), loggerSetting.getConfiguredLevel())
);
log.debug("....persisted log levels loaded");
}
@Path("/")
@GET
public LoggerSetting getLogger(@QueryParam("loggerName") String loggerName) throws JsonProcessingException {
var logger = loggingServiceRestConnector.getLogger(loggerName);
var jsonNode = mapper.readTree(logger);
return createLoggerSetting(jsonNode);
}
@Path("/available")
@GET
public List<LoggerSetting> getAvailableLoggers() throws JsonProcessingException {
var logger = loggingServiceRestConnector.getLoggers();
var list = new ArrayList<LoggerSetting>();
var jsonNode = mapper.readTree(logger);
for (var node : jsonNode) {
list.add(createLoggerSetting(node));
}
return list;
}
private static LoggerSetting createLoggerSetting(JsonNode jsonNode) {
var loggerSetting = new LoggerSetting();
var name = jsonNode.get("name");
var effectiveLevel = jsonNode.get("effectiveLevel");
var configuredLevel = jsonNode.get("configuredLevel");
if (name != null) {
loggerSetting.setLoggerName(name.asText());
}
if (effectiveLevel != null) {
loggerSetting.setEffectiveLevel(effectiveLevel.asText());
}
if (configuredLevel != null) {
loggerSetting.setConfiguredLevel(configuredLevel.asText());
}
return loggerSetting;
}
@Path("/overridden")
@GET
public Collection<LoggerSetting> getOverriddenLoggers() throws BeanPersistenceException {
return loggingSettingsService.getOverriddenLoggers();
}
@Path("/overridden")
@PUT
public LoggerSetting updateLogger(LoggerSetting logger) throws BeanPersistenceException {
loggingServiceRestConnector.updateLogger(logger.getUniqueKey(), logger.getConfiguredLevel());
// must save override
persistence.update(logger);
return logger;
}
@Path("/overridden")
@DELETE
public LoggerSetting resetLogger(String loggerName) throws BeanPersistenceException, JsonProcessingException {
if (loggerName == null) return null;
var original = persistence.findOriginalById(loggerName);
if (original != null) {
if (original.getConfiguredLevel() != null) {
loggingServiceRestConnector.updateLogger(loggerName, original.getConfiguredLevel());
} else {
loggingServiceRestConnector.updateLogger(loggerName, original.getEffectiveLevel());
}
}
var loggerSetting = getLogger(loggerName);
// must remove override
persistence.remove(loggerSetting);
return loggerSetting;
}
}
I tweak a little bit my code to show what was done without been to explicit
at startup
- call logger-manager to get all the loggers
- save those loggers into original.json
- load the overriden.json that contains all the loggers config
- apply those configs to logger-manager.update(loggername, level)
at runtime
- when a level change, it need to save the new level into oerriden.json
- send the new level to logging-manager
to reset a logger level
- read the original value of the logger from original.json
- sent that lavel to logging-manager
with that.. each time that I kill my application, it will reload my previous loggers settings.
PS. the reason that I created a new controler, it's because I had to respect the same URL that we had for SpringBoot
from quarkus-logging-manager.
Related Issues (20)
- How to customize package hierarchy displayed in "Log Levels" window
- Startup Error during tests HOT 4
- logging-manager-ui not working in native-image build on linux x86 HOT 12
- Click on top left icon yields NOT_FOUND instead of navigating back to Dev UI overview HOT 2
- Dev UI fails to load with this extension if using Quarkus 2.6.1 HOT 6
- Add docs module
- oom on build HOT 4
- quarkus.logging-manager.history-size config not working HOT 3
- Migrate to the new Dev UI
- Authentication with bearer token HOT 7
- Can't build Quarkus core 3.1.0.Final with latest quarkus-logging-manager HOT 3
- Provide option to expose endpoints on different port HOT 4
- Endpoints are not found when the application is build HOT 2
- version 3.0.0 no longer works because of missing javascript files HOT 11
- Unable to build due to missing mvnpm dependency HOT 1
- NullPointer when setting logger level to null HOT 2
- open-api warnings HOT 3
- How to include quarkus-logging-manager in uberJar so it is available to modify logging level during run time HOT 18
- Logging manager UI is not working in native image mode HOT 6
- Upgrade to use latest Quarkus
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quarkus-logging-manager.