Answers for "log file example"

6

making log files in python

import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This is debug message')
logging.info('This is information message')
logging.warning('This is warning message')
logging.error('This is warning message')
Posted by: Guest on July-12-2021
1

logging to a file log4j

// How to log to a file using log4j : 

 String filePath = "D:/Logs/MyFirstLog.log";
 PatternLayout layout = new PatternLayout("%-5p %d %m%n");
 RollingFileAppender appender = new RollingFileAppender(layout, filePath);
 appender.setName("MyFirstLog");
 appender.setMaxFileSize("20MB");
 appender.activateOptions();
 logger.addAppender(appender);
 logger.info("this will be printed in the provided log file");
Posted by: Guest on September-06-2021

Python Answers by Framework

Browse Popular Code Answers by Language