-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from tosoikea/rotation
Added rotation to file target
- Loading branch information
Showing
12 changed files
with
249 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<# | ||
.SYNOPSIS | ||
Replaces the tokens present in the pattern with the values given inside the source (log) object. | ||
.PARAMETER Pattern | ||
Parameter The pattern that defines tokens and possible operations onto them. | ||
.PARAMETER Source | ||
Parameter Log object providing values, if wildcard parameter is not given | ||
.PARAMETER Wildcard | ||
Parameter If this parameter is given, all tokens are replaced by the wildcard character. | ||
.EXAMPLE | ||
Format-Pattern -Pattern %{timestamp} -Wildcard | ||
#> | ||
function Format-Pattern { | ||
[CmdletBinding()] | ||
[OutputType([String])] | ||
param( | ||
[AllowEmptyString()] | ||
[Parameter(Mandatory)] | ||
[string] | ||
$Pattern, | ||
[object] | ||
$Source, | ||
[switch] | ||
$Wildcard | ||
) | ||
|
||
[string] $result = $Pattern | ||
[regex] $tokenMatcher = '%{(?<token>\w+?)?(?::?\+(?<datefmtU>(?:%[ABCDGHIMRSTUVWXYZabcdeghjklmnprstuwxy].*?)+))?(?::?\+(?<datefmt>(?:.*?)+))?(?::(?<padding>-?\d+))?}' | ||
$tokenMatches = @() | ||
$tokenMatches += $tokenMatcher.Matches($Pattern) | ||
[array]::Reverse($tokenMatches) | ||
|
||
foreach ($match in $tokenMatches) { | ||
$formattedEntry = [string]::Empty | ||
$tokenContent = [string]::Empty | ||
|
||
$token = $match.Groups["token"].value | ||
$datefmt = $match.Groups["datefmt"].value | ||
$datefmtU = $match.Groups["datefmtU"].value | ||
$padding = $match.Groups["padding"].value | ||
|
||
if ($Wildcard.IsPresent){ | ||
$formattedEntry = "*" | ||
} | ||
else{ | ||
[hashtable] $dateParam = @{ } | ||
if (-not [string]::IsNullOrWhiteSpace($token)) { | ||
$tokenContent = $Source.$token | ||
$dateParam["Date"] = $tokenContent | ||
} | ||
|
||
if (-not [string]::IsNullOrWhiteSpace($datefmtU)) { | ||
$formattedEntry = Get-Date @dateParam -UFormat $datefmtU | ||
} | ||
elseif (-not [string]::IsNullOrWhiteSpace($datefmt)) { | ||
$formattedEntry = Get-Date @dateParam -Format $datefmt | ||
} | ||
else { | ||
$formattedEntry = $tokenContent | ||
} | ||
|
||
if ($padding) { | ||
$formattedEntry = "{0,$padding}" -f $formattedEntry | ||
} | ||
} | ||
|
||
$result = $result.Substring(0, $match.Index) + $formattedEntry + $result.Substring($match.Index + $match.Length) | ||
} | ||
|
||
return $result | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.