github.com/banzaicloud/operator-tools@v0.28.10/pkg/logger/option.go (about)

     1  // Copyright © 2020 Banzai Cloud
     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 logger
    16  
    17  import (
    18  	"io"
    19  )
    20  
    21  type Option func(*SpinnerLogSink)
    22  
    23  func Out(w io.Writer) Option {
    24  	return func(l *SpinnerLogSink) {
    25  		l.out = w
    26  	}
    27  }
    28  
    29  func Err(w io.Writer) Option {
    30  	return func(l *SpinnerLogSink) {
    31  		l.err = w
    32  	}
    33  }
    34  
    35  func Grouppable() Option {
    36  	return func(l *SpinnerLogSink) {
    37  		l.grouppable = true
    38  	}
    39  }
    40  
    41  func Truncate() Option {
    42  	return func(l *SpinnerLogSink) {
    43  		l.truncate = true
    44  	}
    45  }
    46  
    47  func Color(colors Colors) Option {
    48  	return func(l *SpinnerLogSink) {
    49  		l.colors = colors
    50  	}
    51  }
    52  
    53  func CheckMarkCharacter(m rune) Option {
    54  	return func(l *SpinnerLogSink) {
    55  		l.checkMark = m
    56  	}
    57  }
    58  
    59  func ErrorMarkCharacter(m rune) Option {
    60  	return func(l *SpinnerLogSink) {
    61  		l.errorMark = m
    62  	}
    63  }
    64  
    65  func SeparatorCharacter(m rune) Option {
    66  	return func(l *SpinnerLogSink) {
    67  		l.separatorCharacter = m
    68  	}
    69  }
    70  
    71  func WithName(name string) Option {
    72  	return func(l *SpinnerLogSink) {
    73  		l.names = append(l.names, name)
    74  	}
    75  }
    76  
    77  func WithTime(format string) Option {
    78  	return func(l *SpinnerLogSink) {
    79  		l.timeFormat = format
    80  		l.showTime = true
    81  	}
    82  }