I use java.util.logger. I create and call it like this:

LogManager man = LogManager.getLogManager(); try { manager.readConfiguration(getAssets().open("log.properties")); logger=Logger.getLogger("MyApp"); } catch (IOException e) { e.printStackTrace(); } logger.info("AAAAAAAAAAAAAAAAA"); 

Its configuration is:

 # Глобальные настройки handlers = java.util.logging.FileHandler # Конфигурация сохранения в файл java.util.logging.FileHandler.level = ALL java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.FileHandler.limit = 1000000 java.util.logging.FileHandler.pattern = /storage/sdcard0/Android/data/log.txt 

The configuration pulls up normally. No errors. Only the log file on the specified path does not appear. What am I doing wrong?

  • what's your logger ? - Dred
  • java.util.logging.Logger - Streletz
  • Maybe the application does not find the file with the settings or it does not have permission to write to the directory you specified? Try to use the code on the similarity as here in paragraph 5 - Dred
  • It seems that the logger does not write anything, because the file is not attached to it. Although it may be reading the wrong configuration. If this is the case, then look for all configuration files and add settings there. - Roman C

1 answer 1

Understood himself. If everything is configured correctly, especially in terms of file paths, it works.

 log = Logger.getLogger("MyAppClass"); File f = new File(getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS), "log.txt"); if (!f.exists()) { f.createNewFile(); } FileHandler handler = new FileHandler(f.getAbsolutePath(), true); log.addHandler(handler);