github.com/blend/go-sdk@v1.20220411.3/logger/fatal_exit.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package logger
     9  
    10  import (
    11  	"os"
    12  	"sync"
    13  )
    14  
    15  var (
    16  	_log     *Logger
    17  	_logInit sync.Once
    18  )
    19  
    20  func ensureLog() {
    21  	_logInit.Do(func() { _log = MustNew(OptEnabled(Info, Debug, Warning, Error, Fatal)) })
    22  }
    23  
    24  // FatalExit will print the error and exit the process with exit(1).
    25  func FatalExit(err error) {
    26  	ensureLog()
    27  	_log.Fatal(err)
    28  	os.Exit(1)
    29  }