Log4j2 not to create new log file after my application restart - log4j2

I am using Log4j2. My log file name has time stamp like this: app.${date:yyyy-M-dd_hh-mm-ss}.log. I have set max file size to 10MB using SizeBasedTriggeringPolicy. We are good as long as application running. After application restart, new log file getting created even though current log file not reached to the max size due to application restart. Is there any way to use the old log file instead of creating new log file after application restart?

Not with a date in the name. Log4j will resolve the lookup in the name every time the Appender is recreated. There is no way to say "use the date of the newest file that hasn't exceeded the max".

Related

log4j2 starting from 1 after restarting application

Hi I am using log4j2 and using rollover based on time and size. I am using file name as Application.log ,when rollover happens , previous filename appends with index but after system restarts count is again starting from 1 instead of continuing from previous count and its overwriting all existing files. is there way I can avoid it?
if last file name was Application.log.10
if I restart application, when next file roll over it should continue from 11.

Serilog - Log full of NUL characters

I have a Serilog implementation on a C# application. While debugging in our development environment we like to have the log file open in a text editor, like Notepad++.
As I debug and test I like to clean the log file as I go by deleting all the text and saving the file - while the application is still running.
When the application then next writes a log entry, the log is filled with 'NUL' characters.
It is as through Serilog wants to continue to append the log at the last known index point.
I just want it to write cleanly at the start of the log file again.
Is there is a way to do this?
I don't recall having this outcome when using Log4Net.

Grails console open with default or last file

Is there a way to configure grails console to open either with default file or with last opened file?
If you are worried about closing the console every time you bounce the app or do any kind of change that would involve a compile/run-app, then you can use the console plugin instead.
You do not have to close the browser while the restart is in process. I hope this would quench the thirst for your console to some extent. :)

NSLog / Log4Cocoa console logs needs to be saved in file

For my application i need to save all kind of console logs in the text or log file. I am using Log4Cocoa to generating different kind of logs. So how can i save all those console logs into the file? Could anyone please help me.
Thanks
With Log4Cocoa, each logger can have one or more destinations attached to it. So, if you attach a file appender to the root logger object, every log message will be sent to that file. When you initialize the logging system, add something like:
NSString *logFileName = #"path-to-your-log-file";
[[L4Logger rootLogger] addAppender:
[[L4FileAppender alloc] initWithLayout:[L4Layout simpleLayout]
fileName:logFileName];
If you use the L4FileAppender, the file you write to can grow without bounds. So, you might consider using either an L4RollingFileAppender or L4DailyRollingFileAppender instead. The L4RollingFileAppender rolls the file based on file size. The L4DailyRollingFileAppender rolls the file based on time. Despite what the name suggests, you can configure an L4DailRollingFileAppender to roll at different time periods (every minute, every hour, every 1/2 day, etc.).
If you do use a file appender, then you need to give some thought to how you are going to get the log files off of your device, particularly if you need to do logging in the production version of your application.
Much as I like the elegance of Log4Cocoa, I wound up switching to NSLogger (https://github.com/fpillet/NSLogger) and you might want to give it a look.

stacktrace.log file is too large

Inside the target directory of my project, there is a file called stacktrace.log. I have realised size of the file has become more than 3 gigabytes. Is it safe for me to delete this file? Would it cause any file not found exceptions after deleting it? Thanks for your time.
---edit
If it does cause file not found exception, how can I resolve the issue?
stacktrace.log is the default location where Grails writes the unfiltered stack traces of exceptions thrown by the app (for normal logging it filters out stack frames that are "internal" groovy mechanics, but sometimes it can be too aggressive so it's handy to have the full traces available). You can safely delete it and it will get recreated empty next time the app starts.
You can control this in the log4j DSL in Config.groovy, under the appenders block. The default behaviour is equivalent to an appender definition of
file name:'stacktrace', file:'stacktrace.log`
in prod mode and file:'target/stacktrace.log' in dev mode, you could replace it with e.g.
rollingFile name:'stacktrace', file:'stacktrace.log',
maxFileSize:'5MB', maxBackupIndex:2
to limit it to 15MB (the active file plus up to two rolled-over backups).
I guess that is just an log file,If you delete it,the later log will be missing.altough it depends on what logging framwork you are using.
Suggest you to use logback to rolling the log.It can avoid the log to be to Fat.

Resources