Reputation: 2607
I've removed all system.out.println() in my code, and added Logger of apache log4j. But nothing is getting printed in my console. Here is my log4j.properties file
# Define the root logger with appender X
log4j.rootLogger = DEBUG, X
# Set the appender named X to be a File appender
log4j.appender.X=org.apache.log4j.FileAppender
# Define the layout for X appender
log4j.appender.X.layout=org.apache.log4j.PatternLayout
log4j.appender.X.layout.conversionPattern=%m%n
I'm calling logger class as follows
Logger log = Logger.getLogger(PersonImpl.class.getName());
In addition to my log.info(), other logs are getting printed.
DEBUG [http-bio-8080-exec-3] (Table.java:505) - No alter strings for table : hibernate_sequence
DEBUG [http-bio-8080-exec-3] (JtaPlatformInitiator.java:42) - No JtaPlatform was specified, checking resolver
DEBUG [http-bio-8080-exec-3] (JtaPlatformResolverInitiator.java:33) - No JtaPlatformResolver was specified, using default [org.hibernate.engine.transaction.jta.platform.internal.StandardJtaPlatformResolver]
DEBUG [http-bio-8080-exec-3] (StandardJtaPlatformResolver.java:101) - Could not resolve JtaPlatform, using default [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
DEBUG [http-bio-8080-exec-3] (NamedQueryRepository.java:149) - Checking 0 named HQL queries
DEBUG [http-bio-8080-exec-3] (NamedQueryRepository.java:165) - Checking 0 named SQL queries
Upvotes: 1
Views: 5978
Reputation: 1
Try This :
log4j.rootLogger=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
Upvotes: 0
Reputation: 3831
you have only added a FileAppender
(this will cause logs to be written only in file) but you will also need to add a ConsoleAppender
if you want logging to be done in console as well.
it can be done as follows:
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
and also add the name of appender in rootLogger,like this
log4j.rootLogger = DEBUG, X, stdout
apart from this if you want to shutdown Hibernate specific logs, you will have to do
log4j.logger.org.hibernate=fatal or log4j.logger.org.hibernate=off
hope this helps!
Good luck!
Upvotes: 1
Reputation: 1
U can print the logs in file
log4php.appender.services = LoggerAppenderDailyFile
log4php.appender.services.layout = LoggerLayoutPattern
log4php.appender.services.datePattern = Y-m-d
log4php.appender.services.file = /home/Logs_%s
log4php.appender.services.layout.ConversionPattern = "%24d{ISO8601} [%p] %F:%L %m %n"
log4php.rootLogger = debug, services
Upvotes: 0
Reputation: 6876
Use this code to the class at where u want to generate the logs actually.
private static final Logger LOGGER = Logger.getLogger("Class Name Where u used");
LOGGER.error ("string which u want to print");
LOGGER.info("string which u want to print");
LOGGER.warn("string which u want to print");
Use this setting I have do it in my project. It will generate your logs to console as well as logger.out to your project directory
log4j.rootLogger=INFO, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=logger.out
log4j.appender.FILE.MaxFileSize=1MB
log4j.appender.FILE.MaxBackupIndex=100
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.conversionPattern=%m%n
Happy To Help !
Upvotes: 0