# How to deal with log file size under Windows?

**URL:** <https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612>\
**Category:** FAQ\
**Tags:** log-rotate\
**Created:** [June 13, 2024, 7:46am UTC](https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612 "2024-06-13T07:46:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Balage76](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/balage76/32/1129_2.png) [@Balage76](https://forum.storj.io/u/Balage76)\
**Post date:** [June 13, 2024, 7:46am UTC](https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612/1 "2024-06-13T07:46:41Z")

</div>

I run my nodes under Windows and have the default log level set.  
Due to the recently started test, the number of generated log lines increase drastically and this way the file size as well. It is growing by about 1GB / day / node.  
I understand that there are different log levels and I can set it to WARN, but this way I believe I would miss the usefull infos about the startup of the node and the filewalkers.  
Is there a way to limit the log generation to WARN, but store the mentioned infos?

---

<div class="post-metadata">

**Author:** ![Alexey](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alexey/32/41_2.png) [@Alexey](https://forum.storj.io/u/Alexey)\
**Post date:** [June 13, 2024, 8:00am UTC](https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612/2 "2024-06-13T08:00:37Z")

</div>

You need to use a logrotate or custom scripts

> [@How to create daily storagenode logs](https://forum.storj.io/t/topic/6199/5):
>
> are you running in a NAS or Windows or Linux? In Ubuntu I use the “logrotate” command in a cron job to create/compress log files. First you have to make sure you have added in the “Log Location” and “Log level” fields in the “config.yaml” Then look in the “/etc/logrotate.d/” folder, you’ll see a list of files, those are the configs used to rotate logfiles ( usually found in “/var/log/”). I just put a “storj” config file in the logrotate.d/ and it’s done automatically To rotate my logs i use …

> [@Native logs rotation in Windows with a simple PowerShell script](https://forum.storj.io/t/topic/6241/1):
>
> Hello, Unfortunately, in the current windows version of the Storage Node there is no way to rotate or limit the size of the generated logs files. You cannot delete them from the GUI because they are locked by the services processes. Using Clear-Content in PowerShell to reset the files works but there is no easy solution if you want to keep a few days / weeks of logs. I have written a small PowerShell script that can rotate the Storjs Logs without the need of Stop\>Start the services to release …

> [@Best method to redirect logs to independant storage in Linux](https://forum.storj.io/t/topic/8039/10):
>
> Hi phillipe, This is easy to do with logrotate since you can use wildcards to define your paths and files. I placed a logrotate config file in /etc/logrotate.d/ called storagenode . It is a plain text file. My logrotate config file is as follows. Don’t include comments in your config file (there is an uncommented version below). /mnt/logs-usb/storj\*/storagenode\*.log { #the wildcard (\*) characters tell logrotate to look in any subfolder that #begins with storj, and rotate any log that starts wi…

> [@All my nodes keep restarting since last night: "/var/log/supervisor/supervisord.log does not exist"](https://forum.storj.io/t/topic/18206/8):
>
> Yes, the simplest way is to configure logrotate to manage your storagenode logs. It should already be running on your system. I recommend placing a logrotate config specifically for your node(s) in the /etc/logrotate.d folder. For example, I have a file /etc/logrotate.d/storagenode (it can have any name). The file contents are: /path/to/logs/storj\*/storagenode\*.log { su username username weekly maxsize 200M rotate 52 dateext dateformat -%Y%m%d …

> [@How to create daily storagenode logs](https://forum.storj.io/t/topic/6199/5):
>
> are you running in a NAS or Windows or Linux? In Ubuntu I use the “logrotate” command in a cron job to create/compress log files. First you have to make sure you have added in the “Log Location” and “Log level” fields in the “config.yaml” Then look in the “/etc/logrotate.d/” folder, you’ll see a list of files, those are the configs used to rotate logfiles ( usually found in “/var/log/”). I just put a “storj” config file in the logrotate.d/ and it’s done automatically To rotate my logs i use …

---

<div class="post-metadata">

**Author:** ![Balage76](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/balage76/32/1129_2.png) [@Balage76](https://forum.storj.io/u/Balage76)\
**Post date:** [June 13, 2024, 8:09am UTC](https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612/3 "2024-06-13T08:09:15Z")

</div>

Thank you Alexey, but except your second quote, these are about Linux solutions.  
Is it possible to modify/delete the log file in Windows without stopping the node?

---

<div class="post-metadata">

**Author:** ![naxbc](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/naxbc/32/1125_2.png) [@naxbc](https://forum.storj.io/u/naxbc)\
**Post date:** [June 13, 2024, 8:59am UTC](https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612/4 "2024-06-13T08:59:00Z")

</div>

Yap, this is a .bat file I created and then created a Monthly Scheduled Task that runs it:

net stop storagenode  
TIMEOUT /T 10 /NOBREAK  
echo .\> “C:\StorjLogs\storagenode.log”  
TIMEOUT /T 10 /NOBREAK  
net start storagenode

---

<div class="post-metadata">

**Author:** ![Balage76](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/balage76/32/1129_2.png) [@Balage76](https://forum.storj.io/u/Balage76)\
**Post date:** [June 13, 2024, 9:48am UTC](https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612/5 "2024-06-13T09:48:28Z")

</div>

I was thinking about something similar, but this does not solve the issue, I will have 30+GB log files.  
Yes, I can set shorter time range, but then the filewalker will start/run all the time.

Maybe it would be usefull to add one more log level, which is WARN + the info level system messages (like startup + filewalker).

---

<div class="post-metadata">

**Author:** ![naxbc](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/naxbc/32/1125_2.png) [@naxbc](https://forum.storj.io/u/naxbc)\
**Post date:** [June 13, 2024, 12:10pm UTC](https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612/6 "2024-06-13T12:10:42Z")

</div>

Well, set log level to “info” and schedule the task to run monthly.  
By my experience, nodes tend to be less saturated on Sundays.  
My task runs on each last sunday of the month.

---

<div class="post-metadata">

**Author:** ![Ruskiem](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/ruskiem/32/64_2.png) [@Ruskiem](https://forum.storj.io/u/Ruskiem)\
**Post date:** [June 13, 2024, 10:23pm UTC](https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612/7 "2024-06-13T22:23:53Z")

</div>

> [@Balage76](#):
>
> Is it possible to modify/delete the log file in Windows without stopping the node?

I found Yes.

With [this code](https://forum.storj.io/t/native-logs-rotation-in-windows-with-a-simple-powershell-script/6241):

```auto
#-----------------------------------------------
#-------------------- INFOS --------------------
#Script: StorjLogsRotation
#Version: 1.0.1.2
#Date: 27/04/2020
#Author: JDA
#------------------- Variables ------------------
$PathLogLive = 'C:\Program Files\Storj\Storage Node\'
$PathLogArchive = 'F:\logs_auto_clean\'
$DateTimeFormat = "yyyy-MM-dd HH'h'mm"
$RententionInDays = 88888
#-----------------------------------------------
 
 
Function StorjLogsRotation{
 ForEach($L in (Get-ChildItem -LiteralPath $PathLogLive -Filter '*.log' -Recurse:$False)){
  RotateLog -Source $L.FullName -DestinationPath $PathLogArchive -RententionInDays $RententionInDays
 }
}
 
 
Function RotateLog([String]$Source, [String]$DestinationPath,[Int]$RententionInDays){
 $Format = '{0}_[{1}]{2}'
 
 If(Test-Path -LiteralPath $Source){
  $S = Get-Item -LiteralPath $Source
  $Destination = Join-Path -Path $DestinationPath -ChildPath ($Format -F $S.BaseName, ((Get-Date).ToString($DateTimeFormat)), $S.Extension)
 
  If(!(Test-Path -LiteralPath $DestinationPath)){$Null = New-Item -Path $DestinationPath -Type Directory -Force}
  Copy-Item -Path $Source -Destination $Destination -Force
  Clear-Content -LiteralPath $Source -Force
 
  Get-ChildItem -LiteralPath $DestinationPath -File -Filter ($Format -F $S.BaseName, '*',$S.Extension) | ? LastWriteTime -le ((Get-Date).AddDays(-$RententionInDays)) | Remove-Item -ErrorAction SilentlyContinue
 }
}
 
StorjLogsRotation

```

but i had to help my self with autoit .au3 file, and compile to .exe with this 2nd code:

```auto

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3> 
#RequireAdmin
 
;$CmdPid = Run("C:\Users\urmom\Desktop\logrotate.ps1
sleep(3000)
;Powershell.exe -File C:\Users\urmom\Desktop\logrotate.ps1
;powershell.exe -executionpolicy bypass -File C:\Users\urmom\Desktop\logrotate.ps1
;powershell.exe -noexit "& 'C:\Users\urmom\Desktop\logrotate.ps1'"
 
Local $iPid = Run("powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -file C:\Users\" & @UserName & "\Desktop\logrotate.ps1", "c:\", @SW_HIDE, $STDOUT_CHILD)
processWaitClose($iPid)
Local $sOutput = StdoutRead($iPid)

```

because somehow it was the fastest way to solve it for me.  
Probably can be made simpler, but it was working so yeah.  
Obviously You have to update that with Your OWN user name and C:\ file paths!

So basically You Task Schedule the program of 2nd\_code\_theAutoit.exe  
which kick starts the 1st code, made by JDA, and saved in .ps1 file.

I discovered it won’t interrupt the storagenode windows GUI,  
and the logs are cleaned as often as You want,  
i set it daily in Task Scheduler, like every 2 days lately, makes me a 350-500MB files,  
on other busy node 1,2-2,5GB files every 2 days.

---

<div class="post-metadata">

**Author:** ![BigDaddio](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/bigdaddio/32/1135_2.png) [@BigDaddio](https://forum.storj.io/u/BigDaddio)\
**Post date:** [June 14, 2024, 7:24am UTC](https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612/8 "2024-06-14T07:24:30Z")

</div>

This is what i do, I just use a scheduled task on the 1st of the month to run it, creates a new folder for the old exe versions and log files and moves the files into them. pretty basic but works for me…

I should add I mostly use the batch file, the powershell script, while it worked well manually, was a bit problematic setting the scheduled task on a couple of PCs

**Batch file**

```auto
@echo off
set "verPath=C:\Program Files\Storj\Storage Node\old_versions"
set "logPath=C:\Program Files\Storj\Storage Node\logs"

if not exist "%verPath%" (
    mkdir "%verPath%"
)
if exist "%ProgramFiles%\Storj\Storage Node\storagenode.old.*.exe" move "%ProgramFiles%\Storj\Storage Node\storagenode.old.*.exe" "%verPath%"

if not exist "%logPath%" (
    mkdir "%logPath%"
)
net stop storagenode
move "%ProgramFiles%\Storj\Storage Node\storagenode.log" "%logPath%\storagenode-%date:~10,4%-%date:~7,2%-%date:~4,2%_%time:~0,2%-%time:~3,2%.log"
net start storagenode
exit 0

```

**Powershell version**

```auto
$exePath = "C:\Program Files\Storj\Storage Node\old_versions"
$logPath = "C:\Program Files\Storj\Storage Node\logs"

if (!(Test-Path $exePath -PathType Container)) {
    New-Item -ItemType Directory -Force -Path $exePath
}
mv "$env:ProgramFiles\Storj\Storage Node\storagenode.old.*.exe" "$env:ProgramFiles\Storj\Storage Node\old_versions"

if (!(Test-Path $logPath -PathType Container)) {
    New-Item -ItemType Directory -Force -Path $logPath
}
Stop-Service storagenode
mv "$env:ProgramFiles\Storj\Storage Node\storagenode.log" "$env:ProgramFiles\Storj\Storage Node\logs\storagenode-$(date -Format 'yyyy-MM-dd_hh-mm').log"
Start-Service storagenode

```

---

<div class="post-metadata">

**Author:** ![Alexey](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/alexey/32/41_2.png) [@Alexey](https://forum.storj.io/u/Alexey)\
**Post date:** [June 14, 2024, 2:59pm UTC](https://forum.storj.io/t/how-to-deal-with-log-file-size-under-windows/26612/9 "2024-06-14T14:59:56Z")

</div>

You may use my version too:

> **[GitHub - AlexeyALeonov/storagenode\_win\_log\_rotate: Windows GUI storagenode...](https://github.com/AlexeyALeonov/storagenode_win_log_rotate)**
>
> Windows GUI storagenode log rotation script (doesn't compatible with logrotate) - AlexeyALeonov/storagenode\_win\_log\_rotate

or this script:

> [@Native logs rotation in Windows with a simple PowerShell script](https://forum.storj.io/t/topic/6241/1):
>
> Hello, Unfortunately, in the current windows version of the Storage Node there is no way to rotate or limit the size of the generated logs files. You cannot delete them from the GUI because they are locked by the services processes. Using Clear-Content in PowerShell to reset the files works but there is no easy solution if you want to keep a few days / weeks of logs. I have written a small PowerShell script that can rotate the Storjs Logs without the need of Stop\>Start the services to release …

However, perhaps better is to use a native `logrotate`:  
[https://sourceforge.net/p/logrotatewin/wiki/LogRotate/](https://sourceforge.net/p/logrotatewin/wiki/LogRotate/)
