Manage error log in Java - java

I have an issues with the file Error.log which is generate by Java.
It's too big (Currently >10Go) I can't open it with Notepad++/SublimeText etc.. and as it's on a dedicated computer, transfering it with Teamviewers make Teamviewer crash.
I would like to know if there is a way to configure how the error.log file is generated.
I want to have one file each days and only keep the last 7 days.
Can I configure Java to do that ? Or do I need to redirect System.err to a file ?
Thanks.

There are some java libraries you can use to manage log files the most popular log4j. So if you can edit the source code, this library can help achieve what you want. Besides that there are some tools that can handle large log files and give you search functionnality, edit reports and so on. try look for splunk, elasticsearch, kibana ..

If you have source code available just change log4j configuration. If not then try following
create a job which checks consistently to the log file and rename this when size exceeds some configurable value.

Related

How to avoid log4j output external modification

I had a request to find a solution for making a log file secure from editing from the user (not root user) running the JBoss instance of an application (Linux environment)
First idea I had is to use the chattr +a from root user to allow only the appending of new raw in the log file.
But the Log4j file is configured to rotate the file each day and for this reason I suppose that I should repeat the chattr command for each file created everyday.
I also not sure that the past day file in its "append only" state can be zipped from rotation.
Any suggestion or alternative way to proceed is welcomed.
One way is to create your own "daily rolling file appender". In a similar situation, I created a file appender based on the CustodianDailyRollingFileAppender (see for more information the answers in this question). Put your custom version in a "log4j-custom.jar" and place that in the JBoss common lib-directory. Last step is to update the log4j-configuration file to use the custom file appender.
In your custom file appender you can execute commands (1) to change the file-attributes before and after rolling log-files. Make sure to test your custom rolling file appender with "corner cases" like "there are no previous log-files": I found a couple of (easy to solve) bugs in the original custodian appender.
(1) Or use the new Java 7 POSIX file system options.

Log file for JNLP application - Need suggestion

I'm developing a Java Swing application and enabled them with Java web start feature.
Currently, i'm logging the events in a log file and saving them in jre folder.
Is this a correct way of doing?
If not where can i save the log files?
Note : i've asked the same question in other forum, but unable to get any suggestions.
Better option is to store the log files in System.getProperty("user.home").

Saves game level settings

I have been coding for about a month and I have found ways to adapt around ever problem but one. The problem as you can probably see by the title is how to make a way to make game saves. I am currently creating a very simple game that has about 5 classes of my code and maybe 2 of Java Swing GUI.
I know how I would like to go about the saving process but I have no idea how to do it in my code. How I would like to go about doing this is by making the code print a Number or Integer to a file to represent a Level. For example if you completed level 1 the number in the file would be 1. I have tried some templates for this but none of them work.
I understand how to write to a file but my problem is reading it from a jar or even creating a file then reading it from a place on the computer. I need to know how to find a file URL for different computers because some use Docs and Settings and other Users. Please could someone help.
Since the jar is read only, it can only contain the 'default settings'. See this answer for the general strategy to deal with such a embedded-resource.
Speaking of which (embedded resources) see the info. page for more details on how to access them.
Here is an example of storing and reading a Properties file from the 'current directory'.
As mentioned by #MadProgrammer though, it is safest to put the settings file into a (sub-directory) of user.home, as seen in this answer.
But a properties file is just one option. You might also serialize an object, or write the file in a custom format that your app. knows how to read, for the first two off the top of my head.
Besides 'serialize (in some form) in a File', there is also the Preferences API, or for desktop applications launched using Java Web Start, the PersistenceService. Here is a demo. of the service.
I need to know how to find a file url for different computers because
some use Docs and Settings and other Users
The System property user.home points to the user's home directory
File userHome = new File(System.getProperty("user.home"));

How to analyze JVM crash file hs_err_pidXYZ.log

When working on a webapp in Eclipse and Tomcat (wtp) , tomcat crashes and create a file: hs_err_pid20216.log
I tried to use eclipse MAT to analyse the file but MAT doesn't recognize the file as something it can handle, I tried also DAT and it was the same thing. It won't show in the open file dialog.
What kind of file is it?
What should I use to analyze it?
Do I have to make changes to this file so that it will be possible for these tools to parse it.
The log file is available as a GitHub gist
UPDATE:
See #Dan Cruz reply for more information on how to deal with hs_err_pidXYZ.log file. For curious, the cause of the crash was Jackson being confused by a cyclic relationship (bidirectional one-to-many) but this is another story...
What kind of file it is?
It's a HotSpot error log file in text format.
What should I use to analyze it?
Start by downloading the OpenJDK 6 source bundle. Search through the hotspot *.cpp files for strings in the error log. Review the source files for an explanation of what the error log contains.
For example, using OpenJDK 7 sources, you can find siginfo (the operating system process signal information) in the os::print_siginfo() method of os_linux.cpp, Registers (the CPU registers' values) in the os::print_context() method of os_linux_x86.cpp, etc.
Do I have to make changes to this file sothat it will be possible for these tools to parse it.
That would be impossible since the Eclipse Memory Analyzer requires a heap file, which the HotSpot error log is not.
https://fastthread.io gives a well descriptive analyze on the file. it just need to upload it and it will give following items:
Reason to crash
Recommended Solutions
Active Thread (when app crashed)
Core Dump Location
All threads
...
It's a text file. Open it in an editor and try to understand what it means.

There is an interface/GUI appender for log4j?

I want to show my logs in the GUI in a textfield, list, etc. (something like ImgBurn), but I not found a ready appender that do this. There are an appender to do this?
Currently I doing log to the console without any problems.
Take a look at Apache Chainsaw: this can use the Receiver concept from the recent Log4j builds to display events: http://logging.apache.org/chainsaw/index.html.
If you are looking to do real-time text field display you may need to write your own Receiver class.
There are some good tools available for Free (paid as well) that can parse your log files and present them in better formats with lots of filtering and reporting options as well.
Here is a good list of such tools
Are you looking for a real time log viewer?
I can recommend you OtrosLogViewr. It can tail logs from running applications even on remote servers (using SFTP, FTP, Samba)
Check out the latest developer snapshot of Chainsaw - tons of new features, and when configured to process log files via VFSLogFilePatternReceiver, can tail log files, even between app restarts.
There are a ton of new features in this version compared with the currently-released one - some of the more helpful include search results that are highlighted and aggregated in a table, and the ability to annotate events (click in the 'marker' field)
http://people.apache.org/~sdeboy
Try Glasswall, which appends the log contents on the page if you are running a servlet.
http://code.google.com/p/glasswall/

Categories

Resources