Sfoglia il codice sorgente

make log configurable

Tobias Simetsreiter 3 anni fa
parent
commit
4eec8a2567
2 ha cambiato i file con 12 aggiunte e 11 eliminazioni
  1. 1 1
      gitlab/groupusers.ps1
  2. 11 10
      lib/LogRotate.ps1

+ 1 - 1
gitlab/groupusers.ps1

@@ -10,7 +10,7 @@
 # This Script takes emails from pipe and group and access level from cli to invite them
 $GITLAB_INVITE = "$PSScriptRoot\gitlab-invite.ps1"
 
-Set-LogFile ([IO.Path]::GetFullPath("$PSScriptRoot\..\runtime\groupusers.log"))
+Set-Log ([IO.Path]::GetFullPath("$PSScriptRoot\..\runtime\groupusers-$(hostname)-.log")) 1mb 2
 
 
 foreach ($module in @("ActiveDirectory")){

+ 11 - 10
lib/LogRotate.ps1

@@ -1,8 +1,8 @@
 # all logging settins are here on top
 $logFile = "log-$(gc env:computername).log"
 $logLevel = "DEBUG" # ("DEBUG","INFO","WARN","ERROR","FATAL")
-$logSize = 1mb # 30kb
-$logCount = 10
+$logSize = "100b"
+$logCount = 3
 # end of settings
 
 function Write-Log-Line ($line) {
@@ -10,8 +10,14 @@ function Write-Log-Line ($line) {
     Write-Host $Line
 }
 
-Function Set-Logfile ($path) {
-    $script:logFile = $path
+Function Set-Log {
+    param([string]$fileName, [int64]$filesize = 1mb , [int] $logcount = 5)
+
+    $script:logFile  = $fileName
+    $script:logSize  = $filesize
+    $script:logCount = $logcount
+
+    Reset-Log -fileName $fileName -filesize $filesize -logcount $logcount
 }
 
 # http://stackoverflow.com/a/38738942
@@ -55,7 +61,7 @@ function Reset-Log
 { 
     # function checks to see if file in question is larger than the paramater specified 
     # if it is it will roll a log and delete the oldes log if there are more than x logs. 
-    param([string]$fileName, [int64]$filesize = 1mb , [int] $logcount = 5) 
+    param([string]$fileName, [int64]$filesize = 1mb , [int] $logcount = 5)
      
     $logRollStatus = $true 
     if(test-path $filename) 
@@ -126,8 +132,3 @@ function Reset-Log
     } 
     $LogRollStatus 
 } 
-
-# to null to avoid output
-$Null = @(
-    Reset-Log -fileName $logFile -filesize $logSize -logcount $logCount
-)