From 5664caafb34eea6635fe332d1d79ee11e2ac6866 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Thu, 10 Sep 2020 17:02:04 -0700 Subject: [PATCH] Move logging into its own file --- eng/common/scripts/common.ps1 | 36 +++--------------------------- eng/common/scripts/logging.ps1 | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 33 deletions(-) create mode 100644 eng/common/scripts/logging.ps1 diff --git a/eng/common/scripts/common.ps1 b/eng/common/scripts/common.ps1 index e73654cd106..4caaacc4e2c 100644 --- a/eng/common/scripts/common.ps1 +++ b/eng/common/scripts/common.ps1 @@ -8,6 +8,7 @@ $EngScriptsDir = Join-Path $EngDir "scripts" . (Join-Path $EngCommonScriptsDir SemVer.ps1) . (Join-Path $EngCommonScriptsDir ChangeLog-Operations.ps1) . (Join-Path $EngCommonScriptsDir Package-Properties.ps1) +. (Join-Path $EngCommonScriptsDir logging.ps1) # Setting expected from common languages settings $Language = "Unknown" @@ -20,43 +21,12 @@ $EngScriptsLanguageSettings = Join-path $EngScriptsDir "Language-Settings.ps1" if (Test-Path $EngScriptsLanguageSettings) { . $EngScriptsLanguageSettings } -if ($null -eq $LanguageShort) +if (-not $LanguageShort) { $LangaugeShort = $Language } -if ($null -eq $isDevOpsRun) -{ - $isDevOpsRun = ($null -ne $env:SYSTEM_TEAMPROJECTID) -} # Transformed Functions $GetPackageInfoFromRepoFn = "Get-${Language}-PackageInfoFromRepo" $GetPackageInfoFromPackageFileFn = "Get-${Language}-PackageInfoFromPackageFile" -$PublishGithubIODocsFn = "Publish-${Language}-GithubIODocs" - -function LogHelper ($logType, $logArgs) -{ - if ($isDevOpsRun) - { - Write-Host "##vso[task.LogIssue type=$logType;]$logArgs" - } - else - { - Write-Warning "$logArgs" - } -} - -function LogWarning -{ - LogHelper -logType "warning" -logArgs $args -} - -function LogError -{ - LogHelper -logType "error" -logArgs $args -} - -function LogDebug -{ - LogHelper -logType "debug" -logArgs $args -} \ No newline at end of file +$PublishGithubIODocsFn = "Publish-${Language}-GithubIODocs" \ No newline at end of file diff --git a/eng/common/scripts/logging.ps1 b/eng/common/scripts/logging.ps1 new file mode 100644 index 00000000000..19a6fa5bc36 --- /dev/null +++ b/eng/common/scripts/logging.ps1 @@ -0,0 +1,40 @@ +if (-not $isDevOpsRun) +{ + $isDevOpsRun = ($null -ne $env:SYSTEM_TEAMPROJECTID) +} + +function LogWarning +{ + if ($isDevOpsRun) + { + Write-Host "##vso[task.LogIssue type=warning;]$args" + } + else + { + Write-Warning "$args" + } +} + +function LogError +{ + if ($isDevOpsRun) + { + Write-Host "##vso[task.LogIssue type=error;]$args" + } + else + { + Write-Error "$args" + } +} + +function LogDebug +{ + if ($isDevOpsRun) + { + Write-Host "##vso[task.LogIssue type=debug;]$args" + } + else + { + Write-Debug "$args" + } +} \ No newline at end of file