Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java logger errorAdd Answer

#SET LEVEL of ROOT-LOGGER, you will like to have Debug in local, but in prod you may just want WARN and ABOVE. This setting is done here!
log4j.rootLogger=debug, stdout, R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number. (basically, format of log)
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

# THIS IS WHERE YOU WILL HAVE ALL THE LOG WRITTEN
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=/var/log/applogs/example.log

# Maximum size of log file, usually we keep 10MB
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file, usually we keep 10
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
Comment

java logger errorAdd Answer

public class MyClass{

  private static Logger logger = Logger.getLogger(MyClass.class);

  public ReturnType myMethod(Param p, Param2 p2) {
    ....
    ....
    try {
      ..    
    } catch(MyException e) {
       logger.log("Exceptions happen!", e); //this will put all the details in log file configured earlier
    }
    ....
  }

  ....
}
Comment

PREVIOUS NEXT
Code Example
Java :: origin model color 
Java :: How authentication manager works in spring security 
Java :: RedisCacheManager json serializer 
Java :: check is element present in queue java 
Java :: candies price hackerearth solution in java 
Java :: correct lcd initialize 
Java :: iterade dict javacirpt 
Java :: Program to check Vowel or Consonant using Switch Case 
Java :: spring converter in initbinder 
Java :: exemple javafx 
Java :: Java object of the file 
Java :: Rotate Vector by an angle 
Java :: what is method overriding in java 
Java :: how to use a switch statement in java 
Java :: okhttp3, android okhttp 
Java :: ascii values to display certain characters in java 
Java :: calculate number of weeks between two dates 
Java :: java deserialize json object 
Java :: number of digits program in java 
Java :: update role spring security 
Java :: java button with jpg image 
Java :: reverse an android application 
Java :: java manipulate alphabet list 
Sql :: fatal error: libpq-fe.h: No such file or directory 
Sql :: GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 
Sql :: how to get non integer value in sql 
Sql :: mysql workbench in ubuntu 14.04 
Sql :: starts and end with vowel sql 
Sql :: mac xampp mysql not starting 
Sql :: .... ERROR! The server quit without updating PID file mysql centos 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =