File: logging.ps1

package info (click to toggle)
python-azure 20251104%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 770,224 kB
  • sloc: python: 6,357,217; ansic: 804; javascript: 287; makefile: 198; sh: 193; xml: 109
file content (125 lines) | stat: -rw-r--r-- 2,995 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
function Test-SupportsDevOpsLogging() {
  return ($null -ne $env:SYSTEM_TEAMPROJECTID)
}

function Test-SupportsGitHubLogging() {
  return ($null -ne $env:GITHUB_ACTIONS)
}

function LogInfo {
  Write-Host "$args"
}

function LogNotice {
  if (Test-SupportsGitHubLogging) {
    Write-Host ("::notice::$args" -replace "`n", "%0D%0A")
  }
  else {
    # No equivalent for DevOps
    Write-Host "[Notice] $args"
  }
}

function LogNoticeForFile($file, $noticeString) {
  if (Test-SupportsGitHubLogging) {
    Write-Host ("::notice file=$file,line=1,col=1::$noticeString" -replace "`n", "%0D%0A")
  }
  else {
    # No equivalent for DevOps
    Write-Host "[Notice in file $file] $noticeString"
  }
}

function LogWarning {
  if (Test-SupportsDevOpsLogging) {
    Write-Host ("##vso[task.LogIssue type=warning;]$args" -replace "`n", "%0D%0A")
  }
  elseif (Test-SupportsGitHubLogging) {
    Write-Host ("::warning::$args" -replace "`n", "%0D%0A")
  }
  else {
    Write-Host "$args" -ForegroundColor Yellow
  }
}

function LogSuccess {
  $esc = [char]27
  $green = "${esc}[32m"
  $reset = "${esc}[0m"

  Write-Host "${green}$args${reset}"
}

function LogErrorForFile($file, $errorString)
{
  if (Test-SupportsDevOpsLogging) {
    Write-Host ("##vso[task.logissue type=error;sourcepath=$file;linenumber=1;columnnumber=1;]$errorString" -replace "`n", "%0D%0A")
  }
  elseif (Test-SupportsGitHubLogging) {
    Write-Host ("::error file=$file,line=1,col=1::$errorString" -replace "`n", "%0D%0A")
  }
  else {
    Write-Host "[Error in file $file]$errorString" -ForegroundColor Red
  }
}

function LogError {
  if (Test-SupportsDevOpsLogging) {
    Write-Host ("##vso[task.LogIssue type=error;]$args" -replace "`n", "%0D%0A")
  }
  elseif (Test-SupportsGitHubLogging) {
    Write-Host ("::error::$args" -replace "`n", "%0D%0A")
  }
  else {
    Write-Host "$args" -ForegroundColor Red
  }
}

function LogDebug {
  if (Test-SupportsDevOpsLogging) {
    Write-Host "[debug]$args"
  }
  elseif (Test-SupportsGitHubLogging) {
    Write-Host "::debug::$args"
  }
  else {
    Write-Debug "$args"
  }
}

function LogGroupStart() {
  if (Test-SupportsDevOpsLogging) {
    Write-Host "##[group]$args"
  }
  elseif (Test-SupportsGitHubLogging) {
    Write-Host "::group::$args"
  }
}

function LogGroupEnd() {
  if (Test-SupportsDevOpsLogging) {
    Write-Host "##[endgroup]"
  }
  elseif (Test-SupportsGitHubLogging) {
    Write-Host "::endgroup::"
  }
}

function LogJobFailure() {
  if (Test-SupportsDevOpsLogging) {
    Write-Host "##vso[task.complete result=Failed;]"
  }
  # No equivalent for GitHub Actions.  Failure is only determined by nonzero exit code.
}

function ProcessMsBuildLogLine($line) {
  if (Test-SupportsDevOpsLogging) {
    if ($line -like "*: error*") {
      return ("##vso[task.LogIssue type=error;]$line" -replace "`n", "%0D%0A")
    }
    elseif ($line -like "*: warning*") {
      return ("##vso[task.LogIssue type=warning;]$line" -replace "`n", "%0D%0A")
    }
  }
  return $line
}