Last active
March 17, 2019 09:14
-
-
Save ezhov-da/2693b3f334bb1a2b2485d5b075176a24 to your computer and use it in GitHub Desktop.
java класс для логирования в консоль и файл
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
настройки файла логирования: | |
handlers=ru.ezhov.schedulerproductiontasks.tools.ConsoleFileHandler | |
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter | |
java.util.logging.ConsoleHandler.limit=10000 | |
java.util.logging.ConsoleHandler.count=1 | |
java.util.logging.FileHandler.pattern=spt.log | |
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter | |
java.util.logging.FileHandler.count=1 | |
java.util.logging.FileHandler.append=false | |
java.util.logging.FileHandler.level=ALL | |
java.util.logging.FileHandler.encoding=cp1251 | |
package ru.ezhov.schedulerproductiontasks.tools; | |
import java.util.logging.ConsoleHandler; | |
import java.util.logging.FileHandler; | |
import java.util.logging.Level; | |
import java.util.logging.LogRecord; | |
import java.util.logging.Logger; | |
/** | |
* класс. который выводит лог и в консоль и в файл | |
* <p> | |
* @author ezhov_da | |
*/ | |
public class ConsoleFileHandler extends ConsoleHandler | |
{ | |
private static final Logger LOG = Logger.getLogger(ConsoleFileHandler.class.getName()); | |
private FileHandler fileHandler; | |
public ConsoleFileHandler() | |
{ | |
try | |
{ | |
fileHandler = new FileHandler(); | |
} catch (Exception ex) | |
{ | |
LOG.log(Level.SEVERE, null, ex); | |
} | |
} | |
@Override | |
public void close() | |
{ | |
super.close(); | |
if (fileHandler != null) | |
{ | |
fileHandler.close(); | |
} | |
} | |
@Override | |
public void publish(LogRecord record) | |
{ | |
super.publish(record); | |
if (fileHandler != null) | |
{ | |
fileHandler.publish(record); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment