-1

I'm working in an API Rest, and I need to have an specific log file named like my organization. When I'm creating or editing an organization my API must create its file if isn’t exists and then save its data. I already have this parameters in my application.properties with a default path file.

logging.file=/Users/xxxxxxxxx/application.log

In my Java class, specifically in my edit method I'm creating the file if isn’t created.

 String fileLog = "/Users/xxxxxxxxxxxx/logs/" + orgId + ".log";
 File file = new File(fileLog);
 BufferedWriter bw;
 if (!file.exists()) {
    // crea el archivo para la Org si no existe
    bw = new BufferedWriter(new FileWriter(file));
 }

Finally I set the default definition of my (logging.file), defining the new log file for this organization.

PropertiesConfiguration config = new 
PropertiesConfiguration("/Users/xxxxxxxx/application.properties");
config.setProperty("logging.file", "/Users/xxxxxxxxxxxx/logs/" + 
orgId + ".log");
config.save();

My last problem is: How to reset the log manager without restart my server?

Violet48
  • 1
  • 2

1 Answers1

0

The easiest way would be using application.properties. Most commonly customized are:

logging.file= # Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.
logging.file.max-history=0 # Maximum of archive log files to keep. Only supported with the default logback setup.
logging.file.max-size=10MB # Maximum log file size. Only supported with the default logback setup.
Andronicus
  • 25,419
  • 17
  • 47
  • 88