|
| 1 | +// Copyright 2025 Flant JSC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package retry |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/name212/govalue" |
| 19 | + |
| 20 | + "github.com/deckhouse/lib-dhctl/pkg/log" |
| 21 | +) |
| 22 | + |
| 23 | +type GlobalInterruptChecker func() bool |
| 24 | + |
| 25 | +func SetGlobalInterruptChecker(checker GlobalInterruptChecker) { |
| 26 | + if govalue.IsNil(checker) { |
| 27 | + return |
| 28 | + } |
| 29 | + |
| 30 | + globalInterruptChecker = checker |
| 31 | +} |
| 32 | + |
| 33 | +// SetGlobalDefaultLogger |
| 34 | +// Deprecated: |
| 35 | +// global logger used for backward compatibility in dhctl with |
| 36 | +// deprecated functions NewLoop and NewSilentLoop |
| 37 | +// Please use NewLoopWithParams and NewSilentLoopWithParams |
| 38 | +func SetGlobalDefaultLogger(logger log.Logger) { |
| 39 | + if govalue.IsNil(logger) { |
| 40 | + return |
| 41 | + } |
| 42 | + |
| 43 | + defaultLogger = logger |
| 44 | +} |
| 45 | + |
| 46 | +var ( |
| 47 | + globalInterruptChecker GlobalInterruptChecker = func() bool { return false } |
| 48 | + defaultLogger log.Logger = log.NewDummyLogger(false) |
| 49 | + silentLogger = log.NewSilentLogger() |
| 50 | +) |
| 51 | + |
| 52 | +func getDefaultSilentLogger() *log.SilentLogger { |
| 53 | + switch defaultLogger.(type) { |
| 54 | + case *log.TeeLogger: |
| 55 | + return defaultLogger.SilentLogger() |
| 56 | + default: |
| 57 | + return silentLogger |
| 58 | + } |
| 59 | +} |
0 commit comments