Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions ChocoLogParse/ChocoLog.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
$style = if ($_.exitCode -eq 0) {
$PSStyle.Foreground.White
if ($script:ChocoLogNoColor) {
[String]::Format("{0}", $_.exitCode)
} else {
$PSStyle.Foreground.Yellow
$style = if ($_.exitCode -eq 0) {
$PSStyle.Foreground.White
} else {
$PSStyle.Foreground.Yellow
}
[String]::Format("{0}{1}{2}", $style, $_.exitCode, $PSStyle.Reset)
}
[String]::Format("{0}{1}{2}", $bg, $_.exitCode, $PSStyle.Reset)
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
Expand Down
3 changes: 3 additions & 0 deletions ChocoLogParse/ChocoLogParse.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
}
}

# Initialize module variable for color control (default to colored output)
$script:ChocoLogNoColor = $false

# Add our custom formatter that needed classes first
$format = Join-Path -Path $PSScriptRoot -ChildPath 'ChocoLog.format.ps1xml'
Update-FormatData -PrependPath $format
Expand All @@ -23,7 +26,7 @@
[ChocoLog]
)
# Get the internal TypeAccelerators class to use its static methods.
$TypeAcceleratorsClass = [psobject].Assembly.GetType(

Check warning on line 29 in ChocoLogParse/ChocoLogParse.psm1

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (psobject) Suggestions: (isobject, isObject, project, object, subject)
'System.Management.Automation.TypeAccelerators'
)
# Ensure none of the types would clobber an existing type accelerator.
Expand Down
12 changes: 10 additions & 2 deletions ChocoLogParse/Public/Get-ChocoLogEntry.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#
.SYNOPSIS
Grab a single session from the latest log file. Defaults to last exection.

Check warning on line 3 in ChocoLogParse/Public/Get-ChocoLogEntry.ps1

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Misspelled word (exection) Suggestions: (execution*, ejection, election, erection, evection)
.DESCRIPTION
Reads the latest log file and grabs the last session
.NOTES
Expand All @@ -8,7 +8,11 @@
.EXAMPLE
Get-ChocoLogEntry

Grabs the laste entry from the latest log

Check warning on line 11 in ChocoLogParse/Public/Get-ChocoLogEntry.ps1

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (laste) Suggestions: (lase, last, late, lasts, latte)
.EXAMPLE
Get-ChocoLogEntry -NoColor

Grabs the latest entry from the latest log without colored output
.PARAMETER Report
This changes the output to be more friendly for reporting
.PARAMETER Path
Expand All @@ -20,6 +24,9 @@
The log4net pattern layout used to parse the log. It is very unlikely that you
need to supply this. The code expects pattern names: time, session, level, and
message.
.PARAMETER NoColor
Disables colored output in the formatter. When specified, the output will be
displayed without ANSI color codes.
#>
function Get-ChocoLogEntry {
[CmdletBinding()]
Expand All @@ -36,20 +43,21 @@
$Filter = 'chocolatey*.log',
[string]
$PatternLayout = '%date %thread [%-5level] - %message',
[switch]$Report
[switch]$Report,
[switch]$NoColor
)
# ToDo:
# - Support searching for a cli entry
# - sub command type (e.g. search, list, upgrade)
# - Exit code
# - Filter to recent time to make sure we get the right one

$entry = Read-ChocoLog -FileLimit 1 -Path $Path -Filter $Filter -PatternLayout $PatternLayout | Select-Object -Last 1
$entry = Read-ChocoLog -FileLimit 1 -Path $Path -Filter $Filter -PatternLayout $PatternLayout -NoColor:$NoColor | Select-Object -Last 1
if ($report) {
# Print out in a format that's useful for Chef logging
Write-Host ('Command: {0}' -F $entry.cli)
Write-Host ('Exit Code: {0}' -F $entry.exitCode )
# This will print out the configuration in a more readble way

Check warning on line 60 in ChocoLogParse/Public/Get-ChocoLogEntry.ps1

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (readble) Suggestions: (readable, ridable, reade, rabble, raddle)
Write-Host "Configuration: `n - "
$entry.Configuration

Expand Down
15 changes: 14 additions & 1 deletion ChocoLogParse/Public/Read-ChocoLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
Read-ChocoLog

This will read the latest Chocolatey.log on the machine.
.EXAMPLE
Read-ChocoLog -NoColor

This will read the latest Chocolatey.log on the machine without colored output.
.PARAMETER Path
The log path you want to parse. This will default to the latest local log.
This can be a directory of logs.
Expand All @@ -23,6 +27,9 @@
The log4net pattern layout used to parse the log. It is very unlikely that you
need to supply this. The code expects pattern names: time, session, level, and
message.
.PARAMETER NoColor
Disables colored output in the formatter. When specified, the output will be
displayed without ANSI color codes.
#>
function Read-ChocoLog {
# This makes PlatyPS sad.
Expand All @@ -41,8 +48,14 @@
[String]
$Filter = 'chocolatey*.log',
[string]
$PatternLayout = '%date %thread [%-5level] - %message'
$PatternLayout = '%date %thread [%-5level] - %message',
[switch]
$NoColor
)

# Set module-level variable to control coloring in formatter
$script:ChocoLogNoColor = $NoColor.IsPresent

$files = Get-Item -Path $Path
if ($files.PSIsContainer) {
$files = Get-ChildItem -Path $Path -Filter $Filter |
Expand Down Expand Up @@ -110,6 +123,6 @@
}

# Return the whole parsed object
Write-Verbose "Returning results in desceding order. Count: $($parsed.Count)"

Check warning on line 126 in ChocoLogParse/Public/Read-ChocoLog.ps1

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (desceding) Suggestions: (descending, deeding, deciding, decoding, desexing)
$parsed.Values | Sort-Object -Descending Time
}
Loading