Skip to content

Commit

Permalink
Initial Push (Copy from Azure DevOps Repo)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schuster, Claudiu committed Jul 19, 2021
1 parent 81ba3a9 commit 0669577
Show file tree
Hide file tree
Showing 9 changed files with 910 additions and 0 deletions.
7 changes: 7 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
assembly-versioning-scheme: MajorMinorPatchTag
assembly-file-versioning-scheme: MajorMinorPatchTag
assembly-informational-format: '{FullSemVer}'
mode: Mainline
branches: {}
ignore:
sha: []
49 changes: 49 additions & 0 deletions Modules/LogApe/LogApe.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Module manifest for module 'LogApe'
#

@{

# Script module or binary module file associated with this manifest
RootModule = 'LogApe.psm1'

# Version number of this module
ModuleVersion = '1.0.0'

# ID used to uniquely identify this module
GUID = 'ea285917-17d8-4cbf-aa7f-ce3e9714c50e'

# Author of this module
Author = 'Schuster, Claudiu (ClaudiuSchuster)'

# Company or vendor of this module
CompanyName = 'claudiuschuster.de'

# Copyright statement for this module
Copyright = 'GPL v3'

# Description of the functionality provided by this module
Description = 'LogApe - Provides advanced logging functionalities with ease of use'

# Minimum version of the PowerShell engine required by this module
PowerShellVersion = '7.0'

# Supported PSEditions
CompatiblePSEditions = 'Core'

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @( 'New-LogApe' )

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# Variables to export from this module
VariablesToExport = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{ PSData = @{} }

}
556 changes: 556 additions & 0 deletions Modules/LogApe/LogApe.psm1

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions Modules/LogApe/en-US/about_LogApe.help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
TOPIC
About LogApe module

SHORT DESCRIPTION
LogApe - Provides advanced logging functionalities with ease of use

LONG DESCRIPTION
Provides advanced ease of use logging functions

e.g.
- (Multi-)Colors in Pipelines & Shells
- An easy interface for Azure Pipelines Logging Commands (Vso* Methods)
- An easy interface for Progress cmdlets
- Additional LogFile Output
- etc.

Take a look at thr Test-Pipeline for some examples.

EXAMPLES
EXAMPLE
Import-Module LogApe
Imports the module to current session if not already imported.
Note: This can be omitted as PowerShell will autoload the module on the first usage of any module cmdlet.
EXAMPLE
Import-Module LogApe -ArgumentList $true
Imports the module with enabled debug messages to current session, if not already imported.
EXAMPLE
Import-Module LogApe -ArgumentList $true -Force
Imports the module with enabled debug messages to current session, even if already imported.
EXAMPLE
Import-Module LogApe -ArgumentList $false $true
Imports the module and supresses all stdout output (if not already imported, not supressing Vso* Methods).
EXAMPLE
Import-Module LogApe -ArgumentList $false $true -Force
Imports the module and supresses all stdout output (even if already imported, not supressing Vso* Methods).
87 changes: 87 additions & 0 deletions Modules/LogApe/en-US/class_LogApe.help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
TOPIC
About [LogApe] class

SHORT DESCRIPTION
Object based [LogApe] interface - Provides advanced logging functionalities with ease of use

LONG DESCRIPTION
- After creation of an class-instance with the New-LogApe cmdlet the visible class-methods
will be available and can be used for easy but advanced logging purposes.
- The initialization of the instance with a configuration is optional, but can be done
by a JSON-file, PSData-file or by a inline hashtable or JSON string.
- All configuration options returned by the GetConfig class-method can be merged back to
the running-configuration with the SetConfig class-method.
The whole instance configuration can be merged at once, or partially step by step by the SetConfig method.
- LogApe does use $global:ModuleDebugMessages to print internal module debug messages.
- If 'Parent' is set with the initialization parameter or at configuration,
the [string]Parent will be used as Msg-Trailing encapsulated in [ ]

<# Default Configuration for LogApe Class/Module #>
@{
DateCulture = 'en-CA'
MsecLog = $true
Debug = $false
LogFile = $null
Parent = $null
ParentColor = $null
ErrorLevelMsgMapping = $null
}

EXAMPLES
EXAMPLE
$l = New-LogApe
Inits a new LogApe instance without configuration (with default configuration).
EXAMPLE
$l = New-LogApe -PSDataFile '.\LogApeTestConfig.psd1'
Inits a new LogApe instance using PowerShellDataFile for configuration.
EXAMPLE
$l = New-LogApe -JsonFile '.\LogApeTestConfig.json'
Inits a new LogApe instance using JsonFile for configuration.
EXAMPLE
$l = New-LogApe @{ Parent = "vSphereClass" } }
Inits a new LogApe instance using inline Hashtable for configuration.
EXAMPLE
$l = New-LogApe '{ "Parent" : "vSphereClass" } }'
Inits a new LogApe instance using inline JSON for configuration.
EXAMPLE
$l.GetConfig();
Returns the configuration of the $l instance/object as Hashtable.
EXAMPLE
$l.GetConfig($true);
Returns the configuration of the $l instance/object as JSON with short-json formatting.
EXAMPLE
$l.GetConfig($true) | ConvertTo-Json;
Another way to return the configuration of the $l instance/object as JSON with default formatting.
EXAMPLE
$l.SetConfigFromJsonFile('.\LogApeTestConfig.json');
Modifying the instance configuration using a JSON-File.
EXAMPLE
$l.SetConfigFromPSDataFile('.\LogApeTestConfig.psd1');
Modifying the instance configuration using a PSD1-File.
EXAMPLE
$l.SetConfig('{ "Parent" : "vSphereClass" }');
Modifying the instance configuration by inline JSON.
EXAMPLE
$l.SetConfig(@{ Parent = "vSphereClass" });
Modifying the instance configuration by inline Hashtable.
EXAMPLE
$l.SetConfig(@{ Debug = $true });
Enable Module Debug Messages
EXAMPLE
$l.SetConfig(@{ ForceDateCulture = "vSphereClass" });
Force ForceDateCulture to 'de-DE'
EXAMPLE
$l.SetConfig(@{ ForceTextCulture = "de-DE" });
Force TestCulture to 'de-DE'
EXAMPLE
$l.SetConfig(@{ LogFile = "C:\temp\log.txt" });
Set Path to Logfile (Output will be Printed to Screen & To LogFile)
EXAMPLE
$l.SetConfig(@{ MsecLog = $false });
Disable Milliseconds Logging
EXAMPLE
$l.SetConfig(@{ Parent = "vSphereClass" });
Set Parent as Msg-Trailing (in [] encapsulated)
EXAMPLE
$l = New-LogApe; $l.Log("Hello World!"); $l.LogNote("Hello Green World!");
Full LogApe Usage Example.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# PowerShell Core Module: LogApe

Provides advanced logging functionalities with ease of use (e.g. Colors in Pipelines & Shells and optionally additional LogFile Output)

Use cmdlet
```javascript
$l = New-LogApe
```
to Create a Module Instance

Use the in Help documented public class methods
```javascript
$l.LogInfo("Hello World!")
$l.LogNote("Hello Green World!")
...
```
55 changes: 55 additions & 0 deletions TestScripts/MultiColorOutput.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
### LogApe Multi Color Output TestScript ###
############################################
Import-Module (Join-Path (Split-Path $PSScriptRoot -Parent) '\Modules\LogApe\') -Force

Write-Host "- - - Default Colored Output Without Multi Color - - -" -ForegroundColor DarkCyan
$l = New-LogApe -D
$l.LogNote("foo")
$l.LogInfo(@("foo"))
$l.LogWarn(@(@("foo"), @("bar")))
$l.LogError(@(@("foo"), @("bar"), @("baz")))
$l.LogDebug(@(@("foo"), @("bar"), @("baz"), @("qux")))

Write-Host "- - - Multi Color Output as Array (Color as ErrLvl or String) - - -" -ForegroundColor DarkCyan
$l = New-LogApe
$l.LogNote(@("foo", 1))
$l.LogNote(@(@("foo", 1)))
$l.LogNote(@(@("foo", 1), @("bar", 2)))
$l.LogNote(@(@("foo", 1), @("bar", 2), @("baz", 3)))
$l.LogNote(@(@("foo", 1), @("bar", 2), @("baz", 3), @("qux", 4)))
$l = New-LogApe
$l.LogInfo(@("foo", 'Green'))
$l.LogInfo(@(@("foo", 'Green')))
$l.LogInfo(@(@("foo", 'Green'), @("bar", 'Yellow')))
$l.LogInfo(@(@("foo", 'Green'), @("bar", 'Yellow'), @("baz", 'Gray')))
$l.LogInfo(@(@("foo", 'Green'), @("bar", 'Yellow'), @("baz", 'Gray'), @("qux", 'Red')))

Write-Host "- - - Multi Color Output as Object (Color as ErrLvl or String) - - -" -ForegroundColor DarkCyan
$l = New-LogApe
$l.LogWarn(@{ Msg = "foo"; Color = 1; })
$l.LogWarn(@(@{ Msg = "foo"; Color = 1; }))
$l.LogWarn(@(@{ Msg = "foo"; Color = 1; }, @{ Msg = "bar"; Color = 0; }))
$l.LogWarn(@(@{ Msg = "foo"; Color = 1; }, @{ Msg = "bar"; Color = 0; }, @{ Msg = "baz"; Color = 3; }))
$l.LogWarn(@(@{ Msg = "foo"; Color = 1; }, @{ Msg = "bar"; Color = 0; }, @{ Msg = "baz"; Color = 3; }, @{ Msg = "qux"; Color = 4; }))
$l = New-LogApe
$l.LogObject(@{ Msg = "foo"; Color = 'White'; }, $null, $null, 4)
$l.LogObject(@(@{ Msg = "foo"; Color = 'White'; }), $null, $null, 4)
$l.LogObject(@(@{ Msg = "foo"; Color = 'White'; }, @{ Msg = "bar"; Color = 'Green'; }), $null, $null, 4)
$l.LogObject(@(@{ Msg = "foo"; Color = 'White'; }, @{ Msg = "bar"; Color = 'Green'; }, @{ Msg = "baz"; Color = 'Gray'; }), $null, $null, 4)
$l.LogObject(@(@{ Msg = "foo"; Color = 'White'; }, @{ Msg = "bar"; Color = 'Green'; }, @{ Msg = "baz"; Color = 'Gray'; }, @{ Msg = "qux"; Color = 'Red'; }), $null, $null, 4)

Write-Host "- - - Mixed Multi Color Output with Default Color Parts (Color as ErrLvl or String) - - -" -ForegroundColor DarkCyan
$l = New-LogApe
$l.Log(@(@{ Msg = "foo"; Color = 0; }, "bar", @{ Msg = "baz"; Color = 'Yellow'; }, "qux"))
$l.Log(@("foo", @{ Msg = "bar"; Color = 2; }, "baz", @{ Msg = "qux"; Color = 'Green'; }))
$l.LogError(@(@("foo", 0), "bar", @("baz", 'Yellow'), "qux"))
$l.LogError(@("foo", @("bar", 'Yellow'), "baz", @("qux", 0)))

Write-Host "- - - Multi Color Output With Parent as Array or Object (Color as ErrLvl or String) - - -" -ForegroundColor DarkCyan
$l = New-LogApe -D -P 'Parent'
$l.LogDebug(@("foo", 1))
$l.LogDebug(@(@("foo", 1)))
$l.LogDebug(@{ Msg = "foo"; Color = 1; })
$l.LogDebug(@(@{ Msg = "foo"; Color = 1; }))
$l.LogDebug(@(@{ Msg = "foo"; Color = 1; }, @{ Msg = "bar"; Color = 'Yellow'; }, @{ Msg = "baz"; Color = 0; }, @{ Msg = "qux"; Color = 'Red'; }))
$l.LogDebug(@(@("foo", 1), @("bar", 'Yellow'), @("baz", 0), @("qux", 'Red')))
86 changes: 86 additions & 0 deletions TestScripts/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Pipeline: azure-pipelines.yml

parameters:
- name: DEBUG__SCRIPT
displayName: '[DEBUG] Script'
type: boolean
default: true
- name: DEBUG__MODULES
displayName: '[DEBUG] Modules'
type: boolean
default: false
- name: DEBUG__SYSTEM
displayName: '[DEBUG] System'
type: boolean
default: false

variables:
- name: System.Debug
value: ${{ parameters.DEBUG__SYSTEM }}

trigger:
branches:
include:
- master
paths:
include:
- TestScripts/*

pool: Power Shell Runner

resources:
repositories:
- repository: Templates_Pipeline
type: git
name: Infrastructure/Templates_Pipeline

jobs:

- job: prerequisites
displayName: Prerequisites
steps:
- template: /pipeline/build/pipeline-template-step-install-update-psmodule.yml@Templates_Pipeline
parameters:
ModuleName:
- LogApe

- job: LogApe_Test
dependsOn: prerequisites
displayName: LogApe Tests
steps:

- pwsh: |
# Import-Module and set DEBUG__MODULES
Import-Module LogApe -ArgumentList ([bool]::TrueString -eq '${{ parameters.DEBUG__MODULES }}')
# Initialize Log-Instance and set DEBUG__SCRIPT
$l = New-LogApe -D:([bool]::TrueString -eq '${{ parameters.DEBUG__SCRIPT }}')
# Some Log-Lines ...
$l.Log("Hello World!")
$l.LogDebug("Hello Debug World!")
(New-LogApe).VsoLog("Hello World!", 'command')
displayName: LogApe Test
continueOnError: true
- pwsh: |
$scriptPath = "./TestScripts/MultiColorOutput.ps1"
(New-LogApe).VsoLog($scriptPath, 'command')
& $scriptPath
displayName: LogApe MultiColorOutput Test
continueOnError: true
- pwsh: |
$file = "$(Agent.TempDirectory)\foo.txt"
Write-Output "Hello World!" > $file
(New-LogApe).VsoUploadArtifact($file, 'foo1')
displayName: LogApe VsoUploadArtifact Test
continueOnError: true
- pwsh: |
$file = "$(Agent.TempDirectory)\foo.txt"
Write-Output "Hello World!" > $file
(New-LogApe).VsoUploadArtifact($file, 'foo2', "logs\tool")
displayName: LogApe VsoUploadArtifact (To Sub-Folders) Test
continueOnError: true
19 changes: 19 additions & 0 deletions pipeline/build/deploy-modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Pipeline: deploy-modules.yml

trigger:
branches:
include:
- master
- function/*
paths:
include:
- Modules/*

resources:
repositories:
- repository: Templates_Pipeline
type: git
name: Infrastructure/Templates_Pipeline

jobs:
- template: /pipeline/build/pipeline-template-job-deploy-psmodules.yml@Templates_Pipeline

0 comments on commit 0669577

Please sign in to comment.