• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

logback SiftingAppender generated log files cannot be deleted untill stop the tomcat server

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are using logback "SiftingAppender" for generating the log files based on the date and other information such as cycle(Each date can have multiple cycles).

Following are the sample logging file names

20150515_1_Job1.log
20150515_2_Job1.log

For the above scenario we are using the following logback configuration.



Following is the java code for logging the details to the specific logs files.



We have some other jobs that do the housekeeping of the old log files with the retention of 2 days(Two day old files will be moved to another location).

But even after the job completes, we are not able to move the file. We suspect that logback is holding the resource and not letting the file to move or delete.

All the jobs are deployed in a single war file in apache tomcat 8 server.

Can anyone suggest how to enforce logback to release the resource after logging is completed?

Regards,
Mayuran
 
Ranch Hand
Posts: 243
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mayuran,

I haven't tried this out myself but from the documentation, there are a couple of things which you might want to try out

1. Set a timeout.
2. Or send an instruction from the code that this appender is no longer needed.

..., it may be easier to pinpoint a location in your code after which a nested appender is no longer needed. If such a location exists, even approximately, log from that location using the FINALIZE_SESSION marker.




Thanks
Srikkanth
 
Mayuran Satchi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srikkanth,

Thanks for your suggestion.
I have tried your suggestion and still i was not able to delete the file while the server is running.

The following is the java class i used to log the messages and immediately i am setting the "FINALIZE_SESSION" marker.



The following is the logback configuration.



Since i was not able to delete the files after all, i have extended the "SiftingAppender" and overwritten the "append" method to forcefully call the "removeStaleComponents" to remove any resources used by the appender. I am not sure whether its the correct way to do or not, but i am able to delete the log files without any problem.

Following is the extended "SiftingAppender" class definition.




Regards,
Mayuran
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic