...

Source file src/github.com/awslabs/amazon-ecr-credential-helper/ecr-login/config/log.go

Documentation: github.com/awslabs/amazon-ecr-credential-helper/ecr-login/config

     1  // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"). You may
     4  // not use this file except in compliance with the License. A copy of the
     5  // License is located at
     6  //
     7  //	http://aws.amazon.com/apache2.0/
     8  //
     9  // or in the "license" file accompanying this file. This file is distributed
    10  // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
    11  // express or implied. See the License for the specific language governing
    12  // permissions and limitations under the License.
    13  
    14  package config
    15  
    16  import (
    17  	"fmt"
    18  	"os"
    19  	"path/filepath"
    20  
    21  	"github.com/mitchellh/go-homedir"
    22  	"github.com/sirupsen/logrus"
    23  )
    24  
    25  func SetupLogger() {
    26  	logrusConfig()
    27  }
    28  
    29  func logrusConfig() {
    30  	logdir, err := homedir.Expand(GetCacheDir() + "/log")
    31  	if err != nil {
    32  		fmt.Fprintf(os.Stderr, "log: failed to find directory: %v", err)
    33  		logdir = os.TempDir()
    34  	}
    35  	// Clean the path to replace with OS-specific separators
    36  	logdir = filepath.Clean(logdir)
    37  	err = os.MkdirAll(logdir, os.ModeDir|0700)
    38  	if err != nil {
    39  		fmt.Fprintf(os.Stderr, "log: failed to create directory: %v", err)
    40  		logdir = os.TempDir()
    41  	}
    42  	file, err := os.OpenFile(filepath.Join(logdir, "ecr-login.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664)
    43  	if err != nil {
    44  		return
    45  	}
    46  	logrus.SetLevel(logrus.DebugLevel)
    47  	logrus.SetOutput(file)
    48  }
    49  

View as plain text