github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/buildpacks/logger.go (about)

     1  /*
     2  Copyright 2019 The Skaffold Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package buildpacks
    18  
    19  import (
    20  	"io"
    21  
    22  	"github.com/buildpacks/pack/pkg/logging"
    23  	"github.com/sirupsen/logrus"
    24  )
    25  
    26  // logger exists to meet the requirements of the pack logger.
    27  type logger struct {
    28  	*logrus.Logger
    29  	out io.Writer
    30  }
    31  
    32  func NewLogger(out io.Writer) logging.Logger {
    33  	l := logrus.New()
    34  	l.SetOutput(out)
    35  
    36  	// By default, logrus prefixes lines with 'INFO[XXX]'.
    37  	l.SetFormatter(new(plainFormatter))
    38  
    39  	return &logger{
    40  		Logger: l,
    41  		out:    out,
    42  	}
    43  }
    44  
    45  type plainFormatter struct{}
    46  
    47  func (f *plainFormatter) Format(entry *logrus.Entry) ([]byte, error) {
    48  	return []byte(entry.Message + "\n"), nil
    49  }
    50  
    51  func (l *logger) Debug(msg string) {
    52  	l.Logger.Debug(msg)
    53  }
    54  
    55  func (l *logger) Info(msg string) {
    56  	l.Logger.Info(msg)
    57  }
    58  
    59  func (l *logger) Warn(msg string) {
    60  	l.Logger.Warn(msg)
    61  }
    62  
    63  func (l *logger) Error(msg string) {
    64  	l.Logger.Error(msg)
    65  }
    66  
    67  func (l *logger) Writer() io.Writer {
    68  	return l.out
    69  }
    70  
    71  func (l *logger) IsVerbose() bool {
    72  	return false
    73  }