Florian Beaufumé
Florian Beaufumé

Reputation: 1796

Log levels configuration with Wildfly Swarm

When developping a Wildfly Swarm based application, how can i configure the logging levels using properties usable from the project-stages.yml?

In other words, what is the equivalent of the "logging.level.com.acme.rest=DEBUG" properties of Spring Boot?

Currently I know that:

Thank you for your time

Upvotes: 1

Views: 4461

Answers (3)

Lasrik
Lasrik

Reputation: 599

In your project-stages.yml you can define the Logging Levels (see Wildfly Swarm Reference Guide for a full list of all options):

swarm:
  logging:
    loggers:
      com.acme.rest:
        level: DEBUG

Upvotes: 5

Rafael Pereira
Rafael Pereira

Reputation: 21

I created a loggingFraction method in order to achieve this objective. Like that:

 protected LoggingFraction logging() {

        String logName = swarm.stageConfig().resolve("application.name").getValue();
        String category = swarm.stageConfig().resolve("logger.category").getValue();

        String levelName  =swarm.stageConfig().resolve("logger.level").getValue();

        final String logFile = System.getProperty("user.dir") + File.separator+
                "target"+File.separator+
                logName+".log";

        LoggingFraction loggingFraction = new LoggingFraction()
                .periodicSizeRotatingFileHandler(logName,(h)->{
                    h.level(Level.valueOf(levelName))
                            .append(true)
                            .suffix(".yyyy-MM-dd")
                            .rotateSize("30m")
                            .enabled(true)
                            .encoding("UTF-8")
                            .maxBackupIndex(2);
                    Map<String,String> fileSpec = new HashMap<>();
                    fileSpec.put("path", logFile);
                    h.file(fileSpec);
                }).logger(GetinApp.class.getPackage().getName(),(l)->{
                    l.level(Level.valueOf(levelName))
                            .handler(logName);
                });;
      })
        List<String> categories = Arrays.asList(category.split(","));
        categories.forEach(c->{
            loggingFraction.logger(c.trim(),l->{
               l.level(Level.valueOf(levelName)).handler(logName);
            });
        });

        return loggingFraction;
    }

So I can declare my own properties on project-stages.yml like:

project-name:
  logger:
    level: DEBUG
    category: com.example.com, org.anotherexample.com

Upvotes: 2

Bob McWhirter
Bob McWhirter

Reputation: 21

You should be able to add a category to the end:

-Dswarm.logging.com.acme.rest=DEBUG

Upvotes: -1

Related Questions