Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
}
18 changes: 17 additions & 1 deletion docs/en-US/Get-ChocoLogEntry.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

## SYNOPSIS
Grab a single session from the latest log file.
Defaults to last exection.

Check warning on line 12 in docs/en-US/Get-ChocoLogEntry.md

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Misspelled word (exection) Suggestions: (execution*, ejection, election, erection, evection)

## SYNTAX

```
Get-ChocoLogEntry [[-Path] <String[]>] [[-Filter] <String>] [[-PatternLayout] <String>] [-Report]
Get-ChocoLogEntry [[-Path] <String[]>] [[-Filter] <String>] [[-PatternLayout] <String>] [-Report] [-NoColor]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
```

Expand All @@ -28,7 +28,7 @@
Get-ChocoLogEntry
```

Grabs the laste entry from the latest log

Check warning on line 31 in docs/en-US/Get-ChocoLogEntry.md

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (laste) Suggestions: (lase, last, late, lasts, latte)

## PARAMETERS

Expand Down Expand Up @@ -99,13 +99,29 @@
Accept wildcard characters: False
```

### -NoColor
Disables colored output in the formatter. When specified, the output will be
Comment thread
HeyItsGilbert marked this conversation as resolved.
displayed without ANSI color codes.
Comment thread
HeyItsGilbert marked this conversation as resolved.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```

### -ProgressAction
{{ Fill ProgressAction Description }}

```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Check warning on line 124 in docs/en-US/Get-ChocoLogEntry.md

View workflow job for this annotation

GitHub Actions / ci / Run Linters

Unknown word (proga) Suggestions: (proa, prog, progs, Prog, prgo)

Required: False
Position: Named
Expand Down
18 changes: 17 additions & 1 deletion docs/en-US/Read-ChocoLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Parses a Chocolatey log into an object that is easier to search and filter.

```
Read-ChocoLog [[-Path] <String[]>] [[-FileLimit] <Int32>] [[-Filter] <String>] [[-PatternLayout] <String>]
[<CommonParameters>]
[-NoColor] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -100,6 +100,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -NoColor
Disables colored output in the formatter. When specified, the output will be
Comment thread
HeyItsGilbert marked this conversation as resolved.
displayed without ANSI color codes.
Comment thread
HeyItsGilbert marked this conversation as resolved.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

Expand Down
4 changes: 2 additions & 2 deletions requirements.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
}
}
'psake' = @{
Version = '4.9.0'
Version = '4.9.1'
}
'BuildHelpers' = @{
Version = '2.0.16'
}
'PowerShellBuild' = @{
Version = '0.6.1'
Version = '0.7.3'
}
'PSScriptAnalyzer' = @{
Version = '1.19.1'
Expand Down
10 changes: 7 additions & 3 deletions tests/ChocoLogParse.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# cSpell:ignore BHPS Ffoo Subkeys
BeforeDiscovery {
if ($null -eq $env:BHPSModuleManifest) {
.\build.ps1 -Task Init
}
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
Expand Down Expand Up @@ -106,7 +109,7 @@ Describe 'Read-ChocoLog' {

Context 'For Single File' {
It 'Parses the correct number of sessions' {
($script:parsed).Count | Should -Be 3
($script:parsed).Count | Should -Be 3
}

It 'Parses the correct number of lines per session' {
Expand Down Expand Up @@ -140,7 +143,8 @@ Describe 'Read-ChocoLog' {
}

It 'Parses the correct number of lines per session' {
$script:multiple[0].logs.Count | Should -Be 9
$multiLine = $script:multiple | Where-Object { $_.Thread -eq 8748 }
$multiLine.logs.Count | Should -Be 9
}
}
}
Expand All @@ -153,7 +157,7 @@ Describe 'Get-ChocoLogEntry' {

Context 'For Single File' {
It 'Parses the correct number of sessions' {
($script:parsedEntry).Count | Should -Be 1
($script:parsedEntry).Count | Should -Be 1
}

It 'Parses the correct number of lines per session' {
Expand Down
Loading