-
Notifications
You must be signed in to change notification settings - Fork 50
/
logging.go
49 lines (45 loc) · 1.03 KB
/
logging.go
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
// © 2022 Nokia.
//
// This code is a Contribution to the gNMIc project (“Work”) made under the Google Software Grant and Corporate Contributor License Agreement (“CLA”) and governed by the Apache License 2.0.
// No other rights or licenses in or to any of Nokia’s intellectual property are granted for any other purpose.
// This code is provided on an “as is” basis without any warranties of any kind.
//
// SPDX-License-Identifier: Apache-2.0
package app
import (
"errors"
"fmt"
"os"
)
func (a *App) logError(err error) {
if err == nil {
return
}
a.Logger.Print(err)
if !a.Config.Log {
fmt.Fprintln(os.Stderr, err)
}
if a.errCh == nil {
return
}
a.errCh <- err
}
func (a *App) checkErrors() error {
if a.errCh == nil {
return nil
}
close(a.errCh)
errs := make([]error, 0)
for err := range a.errCh {
errs = append(errs, err)
}
if len(errs) == 0 {
return nil
}
if a.Config.Log {
for _, err := range errs {
fmt.Fprintln(os.Stderr, err)
}
}
return errors.New("one or more requests failed")
}