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 the files.
Simply save the code below in a .ps1 file and change the variables to you needs. Then every time you start the script (can be scheduled easily in a task) it will:
-
Look for any *.log files in
$PathLogLive
-
Copy all those logs to
$PathLogArchive
in a new file with a datetime suffix (you can change the format with$DateTimeFormat
) -
Clear the existing logs
-
Delete any *.log file in the to
$PathLogArchive
that is older that$RententionInDays
It’s been running on my node on a scheduled task for a few days without issues. Hope this helps!
PowerShell source code:
#-----------------------------------------------
#-------------------- INFOS --------------------
#Script: StorjLogsRotation
#Version: 1.0.1.2
#Date: 27/04/2020
#Author: JDA
#------------------- Variables ------------------
$PathLogLive = 'S:\Storj\Storage Node\'
$PathLogArchive = 'S:\Storj\Storage Node\Logs\'
$DateTimeFormat = "yyyy-MM-dd HH'h'mm"
$RententionInDays = 8
#-----------------------------------------------
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
PS: Depending on your disk speed, every time the logs are rotated there is a small change you loose a few lines of logs.