Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
VertigoRay committed Jan 10, 2023
1 parent 7543656 commit a520ffb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
17 changes: 16 additions & 1 deletion .build/buildPsake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ task Build -Depends BuildManifest {
# }

# Keep getting an error during Publish-Module. Grabbing a copy of the file from the server to see where it's erroring.
Copy-Item 'C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1' -Destination $script:parentModulePath
# Copy-Item 'C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1' -Destination ([IO.Path]::Combine($script:psScriptRootParent.FullName, 'dev'))

$compress = @{
Path = [IO.Path]::Combine($script:psScriptRootParent.FullName, 'dev')
Expand Down Expand Up @@ -411,6 +411,21 @@ task DeployPSGallery {
Deployed with PSDeploy
- https://github.com/RamblingCookieMonster/PSDeploy
#>

<#
PSWriteLog proxy functions are breaking PowerShellGet\PSModule.psm1
Will dive into later if need be ... it's like just Write-Output
For now, unload them all
#>
Remove-Item 'Function:\Write-Debug' -Force -ErrorAction 'Ignore' -Verbose
Remove-Item 'Function:\Write-Error' -Force -ErrorAction 'Ignore' -Verbose
Remove-Item 'Function:\Write-Host' -Force -ErrorAction 'Ignore' -Verbose
Remove-Item 'Function:\Write-Information' -Force -ErrorAction 'Ignore' -Verbose
Remove-Item 'Function:\Write-Output' -Force -ErrorAction 'Ignore' -Verbose
Remove-Item 'Function:\Write-Progress' -Force -ErrorAction 'Ignore' -Verbose
Remove-Item 'Function:\Write-Verbose' -Force -ErrorAction 'Ignore' -Verbose
Remove-Item 'Function:\Write-Warning' -Force -ErrorAction 'Ignore' -Verbose

[IO.DirectoryInfo] $buildOutputModule = [IO.Path]::Combine($script:BuildOutput, $script:thisModuleName)

Write-Host ('[PSAKE DeployPSGallery] APPVEYOR_PROJECT_NAME: {0}' -f $env:APPVEYOR_PROJECT_NAME) -Foregroundcolor 'Magenta'
Expand Down
2 changes: 1 addition & 1 deletion PSWriteLog/Private/Resolve-Error.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Resolve-Error {
## If function was called without specifying an error record, then choose the latest error that occurred
if (-not $ErrorRecord) {
if ($global:Error.Count -eq 0) {
Microsoft.PowerShell.Utility\Write-Information -Message 'The $Error collection is empty' -Tags 'VertigoRay\PSWriteLog','Resolve-Error'
# Microsoft.PowerShell.Utility\Write-Information -Message 'The $Error collection is empty' -Tags 'VertigoRay\PSWriteLog','Resolve-Error'
return
}
Else {
Expand Down
14 changes: 7 additions & 7 deletions PSWriteLog/Private/Write-Log.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function global:Write-Log {
)

begin {
Microsoft.PowerShell.Utility\Write-Information "[Write-Log] BoundParameters: $($MyInvocation.BoundParameters | Out-String)" -Tags 'VertigoRay\PSWriteLog','Write-Log'
# Microsoft.PowerShell.Utility\Write-Information "[Write-Log] BoundParameters: $($MyInvocation.BoundParameters | Out-String)" -Tags 'VertigoRay\PSWriteLog','Write-Log'

# Get the name of this function
[string] $CmdletName = $PSCmdlet.MyInvocation.MyCommand.Name
Expand Down Expand Up @@ -129,7 +129,7 @@ function global:Write-Log {
[string]
$lMessage
)
Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Source (sb): ${Source}" -Tags 'VertigoRay\PSWriteLog','Write-Log'
# Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Source (sb): ${Source}" -Tags 'VertigoRay\PSWriteLog','Write-Log'
$severityMap = @{ # Vaguely based on POSH stream numbers
Debug = 5
Error = 3
Expand Down Expand Up @@ -179,7 +179,7 @@ function global:Write-Log {
if (($DebugMessage -and -not $LogDebugMessage)) { Return }

foreach ($msg in $Message) {
Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Source: $Source" -Tags 'VertigoRay\PSWriteLog','Write-Log'
# Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Source: $Source" -Tags 'VertigoRay\PSWriteLog','Write-Log'
# Write the log entry to the log file if logging is not currently disabled
if (-not $DisableLogging) {
try {
Expand Down Expand Up @@ -207,9 +207,9 @@ function global:Write-Log {
if ($MaxLogFileSizeMB) {
try {
[decimal] $LogFileSizeMB = $FilePath.Length/1MB
Microsoft.PowerShell.Utility\Write-Information "[Write-Log] LogFileSizeMB: $LogFileSizeMB / $MaxLogFileSizeMB" -Tags 'VertigoRay\PSWriteLog','Write-Log'
# Microsoft.PowerShell.Utility\Write-Information "[Write-Log] LogFileSizeMB: $LogFileSizeMB / $MaxLogFileSizeMB" -Tags 'VertigoRay\PSWriteLog','Write-Log'
if ($LogFileSizeMB -gt $MaxLogFileSizeMB) {
Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Log File Needs to be archived ..." -Tags 'VertigoRay\PSWriteLog','Write-Log'
# Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Log File Needs to be archived ..." -Tags 'VertigoRay\PSWriteLog','Write-Log'
# Change the file extension to "lo_"
[string] $archivedOutLogFile = [IO.Path]::ChangeExtension($FilePath.FullName, 'lo_')

Expand All @@ -225,11 +225,11 @@ function global:Write-Log {
# Start new log file and Log message about archiving the old log file
& $getLogLine -sMsg "Maximum log file size [${MaxLogFileSizeMB} MB] reached. Previous log file was renamed to: ${archivedOutLogFile}" | Out-File -FilePath $FilePath.FullName -Append -NoClobber -Force -Encoding 'UTF8' -ErrorAction 'Stop'
} else {
Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Log File does not need to be archived." -Tags 'VertigoRay\PSWriteLog','Write-Log'
# Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Log File does not need to be archived." -Tags 'VertigoRay\PSWriteLog','Write-Log'
}
} catch {
# If renaming of file fails, script will continue writing to log file even if size goes over the max file size
Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Archive Error: ${_}" -Tags 'VertigoRay\PSWriteLog','Write-Log'
# Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Archive Error: ${_}" -Tags 'VertigoRay\PSWriteLog','Write-Log'
}
}
}
Expand Down

0 comments on commit a520ffb

Please sign in to comment.