2

I wanted to store logs in file in the format: [date time]: Log msg . And also supress the date line which comes after every log message while using java.util.logging . The link (java.util.logging: how to suppress date line) says that I have to overwrite logging.properties file, but I'm not able to locate this file on my Mac . Also, if I create new logging.properties file in src/res folder, then how to link the same in my java code? The code I'm using to write logs in file(but in the same old format) is :

public static void main(String[] args) {  

Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);  
FileHandler fh;  

try {  

    // This block configure the logger with handler and formatter  
    fh = new FileHandler("C:/temp/test/MyLogFile.log");  
    logger.addHandler(fh);
    SimpleFormatter formatter = new SimpleFormatter();  
    fh.setFormatter(formatter);  

    // the following statement is used to log any messages  
    logger.info("My first log");  

} catch (SecurityException e) {  
    e.printStackTrace();  
} catch (IOException e) {  
    e.printStackTrace();  
}  

logger.info("Hi How r u?");  
}
Tarishi Jain
  • 254
  • 3
  • 13
  • Got the solution – Tarishi Jain Jun 13 '19 at 10:04
  • If you have a solution it's fine to post your own answer. If you think it's not worth sharing, it might be better to just delete the question. But others with a similar problem will find your question via search engines. – cfrick Jun 13 '19 at 17:29

0 Answers0