I have been newly working on Play framework and the version is 1.2.5. The logs for my application are stored at location where the entire application is installed. I have installed my application package in C:\app location and running it through Java wrapper.
I am confused as my log.properties file do not say anything about the stored location of log, as shown below, but still it is logging in default log folder of play.
Below is the exactly copied log.properties file for my application which is working fine. Few lines are commented but that is how I have received it.
#properties file used for log4j
log4j.rootLogger=ERROR, Console
log4j.logger.play=DEBUG
# Rolling files
#log4j.appender.Rolling=org.apache.log4j.RollingFileAppender
#log4j.appender.Rolling.File=logs/application.log
#log4j.appender.Rolling.MaxFileSize=1MB
#log4j.appender.Rolling.MaxBackupIndex=100
#log4j.appender.Rolling.layout=org.apache.log4j.PatternLayout
#log4j.appender.Rolling.layout.ConversionPattern=%d{DATE} %-5p ~ %m%n
# Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m%n
All I want to know is how Play is storing it there, Is there any class of Play that has this location stored, and How can I configure to change the location of building logs to other drive say E:\logs?
It is responsible for the location of the log folder,
#log4j.appender.Rolling.File=logs/application.log
will generate logs in the application path with a folder logs
you can change it to the desired location E:\logs in the above line to generate logs in the E:
You will find the default settings of logging,
# Logger
# ~~~~~
section in application.conf inside your /conf directory of your play app.
Related
I'm running an Oozie Java workflow (the jar file is in HDFS), and I'd like to add logging functionality to my application. Does anybody know how to do it? Where should I put my "log4j.properties" file? How can I make log4j to output the log to a location in HDFS?
Looking in this documentation, you can try adding oozie-log4j.properties in your oozie directory (where workflow.xml is).
Here are the default settings:
log4j.appender.oozie=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.oozie.RollingPolicy=org.apache.oozie.util.OozieRollingPolicy
log4j.appender.oozie.File=${oozie.log.dir}/oozie.log
log4j.appender.oozie.Append=true
log4j.appender.oozie.layout=org.apache.log4j.PatternLayout
log4j.appender.oozie.layout.ConversionPattern=%d{ISO8601} %5p %c{1}:%L - %m%n
log4j.appender.oozie.RollingPolicy.FileNamePattern=${log4j.appender.oozie.File}-%d{yyyy-MM-dd-HH}
log4j.appender.oozie.RollingPolicy.MaxHistory=720
It also outlines the following restrictions:
In order for Oozie logging to work 100% correctly, the following restrictions must be observed (described below and in the oozie-log4j.properties file):
The appender that Oozie uses must be named "oozie" (i.e. log4j.appender.oozie )
log4j.appender.oozie.RollingPolicy.FileNamePattern must end with "-%d{yyyy-MM-dd-HH}.gz" or "-%d{yyyy-MM-dd-HH}". If it ends with ".gz" the old logs will be compressed when rolled
log4j.appender.oozie.RollingPolicy.FileNamePattern must start with the value of log4j.appender.oozie.File
I have a simple java program (Java version 1.7), which is an email sender, and I want to log some events during its running. So I decided to use org.apache.log4j.Logger for this. I created the log4j.properties file which contains the following:
log4j.rootLogger=INFO, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=Autoemail.log
log4j.appender.file.MaxFileSize=2MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
log4j.appender.file.encoding=UTF-8
This is how I load the configuration:
PropertyConfigurator.configure(cl.getResource("resources/log4j.properties"));
logger = Logger.getLogger("");
logger.info("Auto email sending started...");
where cl is the classloader. When I run this from Eclipse on my localhost, everything works as desired, the log file has been created if didn't exist, and on next run it is appended.
Then I wanted to run this email sender program automatically every day at 7 am. I created the scheduled cron job, which executes the following:
java -jar /var/projects/Autoemail/Autoemail.jar 2>> /var/projects/Autoemail/Autoemail.err
On first run it worked fine, the log file had been created and info or error had been inserted, but since then the program doesn't write any event into it. The jar file runs, because I can see the sent emails. When I started searching for the reason, and ran the command, it showed me a Permission denied error. I checked the rights of the log file, and it was: rw-rw-r--. So I modified, at last to rwxrwxrwx, but still doesn't write the log, and I can't see any error message in the syslog file. The owner doesn't need sudo right, I think. BTW the server is Ubuntu 13/04.
Does anyone have any idea of what can be wrong, what is still needed, or what do I have to do?
I have added log4j.properties file in source folder of project but I am still getting a log4j:error.
Here is my Log4j.properties file:
.rootCategory=DEBUG, R, O
# Stdout
log4j.appender.O=org.apache.log4j.ConsoleAppender
log4j.appender.O=log44j.log
# File
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log4j.log
# Control the maximum log file size
log4j.appender.R.MaxFileSize=100KB
# Archive log files (one backup file here)
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.O.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n
log4j.appender.O.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n
# Define the root logger with appender file
logDir = ../logs
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=logs/${file.name}
log4j.appender.FILE.Append=false
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
Here is the Java exception that I am getting:
log4j:ERROR setFile(null,false) call failed.
java.io.FileNotFoundException: logs (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:809)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:547)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
at org.apache.log4j.Logger.getLogger(Logger.java:104)
at lib.Dashboard.Reports.<init>(Reports.java:34)
at testcases.AmazonDashboard.TC_DB17.main(TC_DB17.java:54)
AmazonDashboardTC_DB17Exception in thread "main" java.lang.NullPointerException
at testcases.AmazonDashboard.TC_DB17.main(TC_DB17.java:131)
Please let me know, how to resolve this exception, as I have tried placing my properties file in root folder and now I have placed in source folder but in both cases I got the above exception.
I suspect that the variable ${file.name} is not substituted correctly. As a result, the value of log4j.appender.FILE.File becomes logs/. As such, Java tries to create a log file named logs/, but probably it is an existing directory, so you get the exception.
As a quick remedy, change the log4j.appender.FILE.File setting to point to file by absolute path, for example /tmp/mytest.log. You should not get an exception.
After that you can proceed to debugging why ${file.name} is not replaced correctly in your runtime environment.
I had the exact same problem. Here is the solution that worked for me: simply put your properties file path in the cmd line this way :
-Dlog4j.configuration=<FILE_PATH> (ex: log4j.properties)
Hope this will help you
i just add write permission to "logs" folder and it works for me
this error is coming because of appender file location you have provided is not reachable with current user access.
Quick Solution, change the log4j.appender.FILE.File setting to point to file using absolute path which location is reachable to the current user you have logged in, for example /tmp/myapp.log. Now You should not get an error.
if it is window7(like mine), without administrative rights cannot write a file at C: drive
just give another folder in log4j.properties file
Set the name of the file
log4j.appender.FILE.File=C:\server\log.out you can see with notepad++
This is your config :
log4j.appender.FILE.File=logs/${file.name}
And this error happened :
java.io.FileNotFoundException: logs (Access is denied)
So it seems that the variable file.name is not set, and java tries to write to the directory logs.
You can force the value of your variable ${file.name} calling maven with this option -D :
mvn clean test -Dfile.name=logfile.log
Have a look at the error -
'log4j:ERROR setFile(null,false) call failed.
java.io.FileNotFoundException: logs (Access is denied)'
It seems there's a log file named as 'logs' to which access is denied i.e it is not having sufficient permissions to write logs. Try by giving write permissions to the 'logs' log file. Hope it helps.
Please changes your log file location to another drive. it will work.
this happen's the permission of creating log file.
To prevent this isue I changed all values in log4j.properties file with directory ${kafka.logs.dir} to my own directory. For example D:/temp/...
Try executing your command with sudo(Super User), this worked for me :)
Run : $ sudo your_command
After than enter the super user password. Thats All..
am using log4j-1.2.15.jar for enable logging .and its writing all logs to a file.
this is what in my log4j.properties.
log4j.rootLogger = DEBUG, fileout
log4j.appender.fileout = log.NewLogForEachRunFileAppender
log4j.appender.fileout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c - %m%n
log4j.appender.fileout.layout = org.apache.log4j.PatternLayout
log4j.appender.fileout.File = D:/log/logs.log
It was working fine when am trying to run this from my local server configured in eclipse.
But the same is not working when i had deployed that into the production development enviornment.This is what am getting in the console.
no output stream or file set for the appender named [fileout]
Can anyone give a solution.?
Your configuration looks ok. I assume the D:/log/logs.log is available in production environment.
You might want to try log4j configuration debugging by setting -Dlog4j.debug on the command line. It often points out useful configuration errors.
I have a log4j properties file which is creating a file inside my tomcat>bin folder but instead can it write the log file to my project's root dir? webapps>test>___?
Here is my log4j properties file contents.
#define the console appender
log4j.appender.consoleAppender = org.apache.log4j.ConsoleAppender
# now define the layout for the appender
log4j.appender.consoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%t %-5p %c{3} - %m%n
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=/test/a.log
log4j.appender.rollingFile.MaxFileSize=10MB
log4j.appender.rollingFile.MaxBackupIndex=2
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%p %t %c - %m%n
# now map our console appender as a root logger, means all log messages will go to this appender
#for console printing
#log4j.rootLogger = DEBUG, consoleAppender
#for file printing
log4j.rootLogger = DEBUG, rollingFile
Try replacing this:
log4j.appender.rollingFile.File=/test/a.log
with this:
log4j.appender.rollingFile.File=../webapps/test/a.log
Note (by Stephen C) - the "../" means this solution depends on whether or not the Tomcat launch mechanism you use makes $CATALINA_HOME the current directory before the JVM that hosts Tomcat. Some do, and some don't.
The log4j configurations understand "${catalina.home}", so ...
log4j.appender.rollingFile.File=${catalina.home}/webapps/test/a.log
However, I don't think it is a good idea to put logs into the webapps tree because they are liable to be blown away if your webapp is redeployed.
Put them in ${catalina.home}/logs instead.
Or better still, put them in the distro-specific conventional place to put application logfiles; e.g. "/var/spool/..." or "/var/log/...".
Putting logfiles in standard places means there are less places for someone else (e.g. the guy who is the backup sysadmin when you are on holiday) to investigate if the file system fills up with old logfiles.