Public/Get-P1Log.ps1

function Get-P1Log {
    <#
    .Synopsis
    Get the logs for a tenant

    .Description
    Return the list of logs of their content.

    .Parameter Tenant
    The tenant name.

    .Parameter LogType
    logService, logManager or logWeb

    .parameter LogName
    The log name to display

    .parameter Wait
    Wait modification on log to display

    .Example
    # Get the list of logs
    Get-P1Log -Tenant Prod

    .Example
    # Get a log for logService and follow it
    Get-P1Log -Tenant Prod -LogType logService -LogName PlannerOneApplication.log -Wait
    #>

    [cmdletbinding()]
    param( 
        [string] $Tenant,
        [string] $LogType,
        [string] $LogName,
        [switch] $Wait
    )
    Process
    {
        if (!(Test-Tenant $Tenant)) {
            Write-Warning "Tenant $Tenant does not exist."
            Write-Warning "Operation canceled."
            return
        }

        $path = Get-LogPathFromTenant $Tenant
        if ($LogType -ne "") {
            $path = $path + $LogType
            if (!(Test-Path $path)) {
                Write-KO "The log type $LogType does not exist."
                return
            }
        }

        if ($LogName -eq "") {
            $logs = Get-ChildItem -Recurse $path -Filter *.log*
            $logInfos = @()
            foreach ($log in $logs) {
                $logInfo = new-object psobject -property @{
                    "LogType" = $log.Directory.Name;
                    "LogName" = $log.Name;
                }

                $logInfos += $logInfo
            }

            Write-Output $logInfos | Format-Table
        } else {
            $path = $path + "\" + $LogName
            if (!(Test-Path $path)) {
                Write-KO "Log $LogType $LogName does not exist"
                return
            } else {
                Get-Content $path -Wait:$Wait.IsPresent
            }
        }
    }
}