cassandra reinstallation not working on ubuntu - java

It was wroking fine some days before all though i changed the size from Xss:168k to 256k and now I am facing this error while starting cassandra,although i have gone through existing solution but that are saying to compare existing file of cassandra.yaml and copy-paste the difference between them but not working for me, i am working on ubntu-13.0.4 getting an error ExceptionInInitializerError ,HeapDumpOnOutOfMemoryError
cassandra -f
xss = -ea -javaagent:/usr/share/cassandra/lib/jamm-0.2.5.jar -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms1024M -Xmx1024M -Xmn256M -XX:+HeapDumpOnOutOfMemoryError -Xss256k
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Couldn't figure out log4j configuration: log4j- server.properties
at org.apache.cassandra.service.CassandraDaemon.initLog4j(CassandraDaemon.java:103)
at org.apache.cassandra.service.CassandraDaemon.<clinit>(CassandraDaemon.java:69)
any help and solution that work out,thanks.what changes do i have to make after reinstallation.
Edit
i have my log file in /etc/cassandra/log4j-tools.properties
# output messages into a rolling log file as well as stdout
log4j.rootLogger=WARN,stderr
# stderr
log4j.appender.stderr=org.apache.log4j.ConsoleAppender
log4j.appender.stderr.target=System.err
log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
log4j.appender.stderr.layout.ConversionPattern=%5p %d{HH:mm:ss,SSS} %m%n

Couldn't figure out log4j configuration: log4j- server.properties
This makes me thing that there is something wrong with your log4j config. The file is located in /test/conf/log4j-server.properties, or maybe its missing. Check this question out, I'd say its very closely related.
This is what the default looks like:
log4j.rootLogger=DEBUG,R
# rolling log file ("system.log
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%5p [%t] %d{ISO8601} %F (line %L) %m%n
log4j.appender.R.File=build/test/logs/system.log

Related

Running java application from batch with flags

I hava jar with class my.package.Foo inside, containing main method.
What is more i have Log4j configurated as a logging system.
I want to print full stack trace while exception is catched, however i read this topic: log4j not printing the stacktrace for exceptions
and i think that i need to use a -XX:-OmitStackTraceInFastThrow flag.
So i'm trying to call my app with command line like this:
java -XX:-OmitStackTraceInFastThrow -cp %JAR_LOCATION:% my.package.Foo
However i'm still missing stacktrace, i get only short exception message.
Here is my log4j config:
log4j.rootLogger=INFO, CONSOLE, FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=log.txt
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Threshold=debug
log4j.appender.FILE.Append=false
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{HH:mm:ss.SSS} %-4p %c{2}.%m%n
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-4p %c{2}.%m%n
What i'm missing?
Try it like this:
set JAR_LOCATION=c:\any folder with spaces\jar
java -XX:-OmitStackTraceInFastThrow -cp "%JAR_LOCATION:~%" my.package.Foo
You have to remove the ":" char from %JAR_LOCATION:%, or use %JAR_LOCATION:~% to de-quote it, and quote it directly at the JAVA command, because the path probably contains spaces.

Jar file ran by cron doesn't write his own log

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?

Error: "setFile(null,false) call failed" when using log4j

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..

log4j truncates stacktrace

I'm having a problem printing the stacktrace to my log file.
Log4j.properties:
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/var/log/app/application.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
log4j.rootLogger=warn, file
log4j.logger.com.app=info, file
log4j.additivity.com.app=false
when I log an exception like this in my class UserGuard.java:
} catch (Exception e) {
log.error("Uncaught error", e);
response.setEntity(new StringRepresentation(" "));
response.setStatus(Status.SERVER_ERROR_INTERNAL);
}
This results in my application.log :
2011-12-28 07:30:03 UserGuard [ERROR] Uncaught error
java.lang.NullPointerException
No stack trace shown. This is really annoying.
Thanks!
Tried with same pom.xml and same log4j.properties on another machine and works ok. Should I think that the problem is my java version?
Your stack traces are most likely getting truncated due to an optimization in Hotspot. The optimization only builds the identical stacktrace a limited number of times, and then future instances of the exception from the same exact place don't build it.
You can either turn off this optimization using the -XX:-OmitStackTraceInFastThrow flag, or go back to earlier logs to find the first instance of this exception occuring (it's logged once, then optimized away later).
See this related StackOverflow question, and this one, and this blog post over here.
There is an enhancement to log4j:
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html

log4j file appender not working

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.

Categories