How to clean the folder of Slicer_Logs?

Operating system: Windows
Slicer version: 4.11.0-2019
Expected behavior: Keep Slicer_Logs folder as small as possible
Actual behavior: it is swelling after each usage

Hi All expertise in Slicer:
I happened to see my C: drive space shrunk and then figure it out that users\Documents\Slicer_Logs folder having lots of history of my slicer usage.

So how to keep it as small as possible? Is there any python/CLI functions so that I may clean it before or after each time usage?

Thanks a lot, Aiden

I’m not familiar with this “Slicer_Logs” directory within Documents. Did you go into Settings->Modules and change “Temporary Directory” from the default location of %LocalAppData%/Temp/Slicer ? This is where Slicer logs are typically found and are usually fairly small in size.

Did you change Settings->Cache which also has a default location of %LocalAppData%/Temp/Slicer/RemoteIO to be in “Slicer_Logs” and then increase the max cache size really large as well? Log files wouldn’t result in such a large file usage, but some cache location could grow large if you set the limit to something really high.

Or by chance have you been writing custom code or using a third party Slicer extension that is using this “Slicer_Logs” location?

Thanks a lot for your quick reply, James.

I guess I did not use a third party slicer extension associated with Slicer_Logs (or, LOL, I do not know it at all).

Yes, I did set up the “Temporary directory” as “C:/Users/Aiden.Zhu/documents/Slicer_Logs”. But it seems I did not really set up a large Cache, here is my settings:

So is there any command I may use to clean cache?
Thanks again.
Aiden

Only the last 10 log files are kept by default (you can change the value in your Slicer-NNN.ini file in LogFiles section “NumberOfFilesToKeep” value), but usually the files are small, so it should not be an issue.

Maybe you have enabled “Developer mode”. In developer mode, CLI module input and output files are not deleted after execution to make debugging easier. You can disable developer mode if this causes an issue for you.

1 Like

@lassoan @jamesobutler
Thanks a lot.
Yeah, I guess it’s just due to my “Developer Mode” on. Then all right for me, I just need pay attention to it to make sure of that I have enough space in C-drive.

Best, Aiden

1 Like

Can I know where the log files go in linux systems?
Can I also get some resources to implement logging in my extension?
How can I inspect core slicer’s logging system?

Current application log:

slicer.app.errorLogModel().filePath

Recent log file paths:

slicer.app.recentLogFiles()

You can use standard Python, VTK, ITK, Qt, console logging - they are all captured in the application log.

You can access all the logs, connect event handlers, etc. through the slicer.app.errorLogModel() object.

1 Like

Ok I get it.

How can I set the number of files that is kept in the log folder? I want to keep all the log files.
If I can’t keep all the log files, what is the maximum number of files I can keep? I don’t want to be limited to only ten. (it seems only 10 files get stored according to the experiment I did.) If I can keep the number of files that can be kept in the log folder, How can I set the number of files to keep programmatically? should I put it in the .slicerrc.py file?

Thanks in advance.

This number is stored in the application settings. I didn’t find it in the GUI, but you can open the Slicer.ini file and change the number for the NumberOfFilesToKeep entry. I don’t think there is a maximum.

1 Like

How can I keep all the log files? the log files goes inside the tmp directory and if I just reboot my or shut down and boot it the next day the whole directory is gone. how can I prevent this? Is there any way to change the cmake files so that the logs goes in the folder where the slicer executable lives? I changed the number of files to keep to 10,000 I need all the log files.

Why do you need to keep all the log files? How many Slicer sessions are you starting and ending a day? If you explain your use case, we might be able to give more pointed advise.

If you are on Linux you might simply add a cronjob to rsync the files to a permanent location (say every 5 minutes).

We need to collect all the details from our custom built slicer such as which functionality the user is using the most; how are they navigating through our modified custom built slicer; what series of operation that led to the crash if at all there is one and how much time user spends working on our components and much more. We also don’t want to make such that their tmp is constantly sending us their log files. We should be able to ssh into their machine and look around the log files if there is a problem. This is our use case. We at least need 1000 log files in a path where it doesn’t get automatically cleaned.

If you have a custom built slicer, I am pretty sure you can control where the files are written?

I do not know where they are in the source code, but a quick github repo search for logfile keyword, returned results both of to your inquiries (e.g., how many log files to keep, as well as their location). It looks like it is

Base/QTGUI/qSlicerApplication.cxx you want to modify

https://github.com/search?q=repo%3ASlicer%2FSlicer+logfile&type=code

Is there any way to change the path using the .ini files where all the configuration goes? I don’t want to modify the core slicer’s code.

You may want to have a look at the SlicerTelemetry extension to get more specific info about what features are being used and how often. Be sure to get user consent before collecting this data.

While it wouldn’t be as clean, you could add custom python code to copy the log file somewhere either with a timer or at application exit (or both).