github.com/hyperledger/aries-framework-go@v0.3.2/pkg/common/log/logger.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package log
     8  
     9  import (
    10  	"github.com/hyperledger/aries-framework-go/component/log"
    11  	spilog "github.com/hyperledger/aries-framework-go/spi/log"
    12  )
    13  
    14  // Log is an implementation of Logger interface.
    15  // It encapsulates default or custom logger to provide module and level based logging.
    16  type Log = log.Log
    17  
    18  // New creates and returns a Logger implementation based on given module name.
    19  // note: the underlying logger instance is lazy initialized on first use.
    20  // To use your own logger implementation provide logger provider in 'Initialize()' before logging any line.
    21  // If 'Initialize()' is not called before logging any line then default logging implementation will be used.
    22  func New(module string) *Log {
    23  	return log.New(module)
    24  }
    25  
    26  // SetLevel - setting log level for given module
    27  //
    28  //	Parameters:
    29  //	module is module name
    30  //	level is logging level
    31  //
    32  // If not set default logging level is info.
    33  func SetLevel(module string, level spilog.Level) {
    34  	log.SetLevel(module, level)
    35  }
    36  
    37  // GetLevel - getting log level for given module
    38  //
    39  //	Parameters:
    40  //	module is module name
    41  //
    42  //	Returns:
    43  //	logging level
    44  //
    45  // If not set default logging level is info.
    46  func GetLevel(module string) spilog.Level {
    47  	return log.GetLevel(module)
    48  }
    49  
    50  // IsEnabledFor - Check if given log level is enabled for given module
    51  //
    52  //	Parameters:
    53  //	module is module name
    54  //	level is logging level
    55  //
    56  //	Returns:
    57  //	is logging enabled for this module and level
    58  //
    59  // If not set default logging level is info.
    60  func IsEnabledFor(module string, level spilog.Level) bool {
    61  	return log.IsEnabledFor(module, level)
    62  }
    63  
    64  // ParseLevel returns the log level from a string representation.
    65  //
    66  //	Parameters:
    67  //	level is logging level in string representation
    68  //
    69  //	Returns:
    70  //	logging level
    71  func ParseLevel(level string) (spilog.Level, error) {
    72  	l, err := log.ParseLevel(level)
    73  
    74  	return l, err
    75  }
    76  
    77  // ShowCallerInfo - Show caller info in log lines for given log level and module
    78  //
    79  //	Parameters:
    80  //	module is module name
    81  //	level is logging level
    82  //
    83  // note: based on implementation of custom logger, callerinfo info may not be available for custom logging provider
    84  func ShowCallerInfo(module string, level spilog.Level) {
    85  	log.ShowCallerInfo(module, level)
    86  }
    87  
    88  // HideCallerInfo - Do not show caller info in log lines for given log level and module
    89  //
    90  //	Parameters:
    91  //	module is module name
    92  //	level is logging level
    93  //
    94  // note: based on implementation of custom logger, callerinfo info may not be available for custom logging provider
    95  func HideCallerInfo(module string, level spilog.Level) {
    96  	log.HideCallerInfo(module, level)
    97  }
    98  
    99  // IsCallerInfoEnabled - returns if caller info enabled for given log level and module
   100  //
   101  //	Parameters:
   102  //	module is module name
   103  //	level is logging level
   104  //
   105  //	Returns:
   106  //	is caller info enabled for this module and level
   107  //
   108  // note: based on implementation of custom logger, callerinfo info may not be available for custom logging provider
   109  func IsCallerInfoEnabled(module string, level spilog.Level) bool {
   110  	return log.IsCallerInfoEnabled(module, level)
   111  }