Last active
July 5, 2018 12:42
-
-
Save eos87/637895 to your computer and use it in GitHub Desktop.
logger
This file contains hidden or 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
import java.io.IOException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import org.apache.log4j.*; | |
/** | |
* | |
* @author e0s87 | |
*/ | |
public class logger { | |
// Define a static logger variable so that it references the Logger instance | |
Date fecha = new Date(); | |
public logger() throws IOException { | |
Logger log = Logger.getLogger(logger.class); | |
SimpleDateFormat formato = new SimpleDateFormat("dd.MM.yyyy"); | |
String fechaAc = formato.format(fecha); | |
PatternLayout defaultLayout = new PatternLayout("%p %c, line %L, %d{dd.MM.yyyy/HH:mm:ss}, %m%n"); | |
RollingFileAppender rollingFileAppender = new RollingFileAppender(); | |
rollingFileAppender.setFile("/tmp/archivo_" + fechaAc + ".log", true, false, 0); | |
//rollingFileAppender.setMaxFileSize("10MB"); | |
//rollingFileAppender.setMaxBackupIndex(5); | |
rollingFileAppender.setLayout(defaultLayout); | |
log.removeAllAppenders(); | |
log.addAppender(rollingFileAppender); | |
log.setAdditivity(false); | |
log.info("Nueva Prueba."); | |
log.info("Exiting application."); | |
} | |
public static void main(String[] args) throws IOException { | |
// Set up a simple configuration that logs on the console. | |
new logger(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment