github.com/mongodb/grip@v0.0.0-20240213223901-f906268d82b9/loggers.go (about)

     1  /*
     2  Basic Logging
     3  
     4  Loging helpers exist for the following levels:
     5  
     6  	Emergency + (fatal/panic)
     7  	Alert + (fatal/panic)
     8  	Critical + (fatal/panic)
     9  	Error + (fatal/panic)
    10  	Warning
    11  	Notice
    12  	Info
    13  	Debug
    14  
    15  These methods accept both strings (message content,) or types that
    16  implement the message.MessageComposer interface. Composer types make
    17  it possible to delay generating a message unless the logger is over
    18  the logging threshold. Use this to avoid expensive serialization
    19  operations for suppressed logging operations.
    20  
    21  All levels also have additional methods with `ln` and `f` appended to
    22  the end of the method name which allow Println() and Printf() style
    23  functionality. You must pass printf/println-style arguments to these methods.
    24  
    25  # Conditional Logging
    26  
    27  The Conditional logging methods take two arguments, a Boolean, and a
    28  message argument. Messages can be strings, objects that implement the
    29  MessageComposer interface, or errors. If condition boolean is true,
    30  the threshold level is met, and the message to log is not an empty
    31  string, then it logs the resolved message.
    32  
    33  Use conditional logging methods to potentially suppress log messages
    34  based on situations orthogonal to log level, with "log sometimes" or
    35  "log rarely" semantics. Combine with MessageComposers to to avoid
    36  expensive message building operations.
    37  */
    38  package grip
    39  
    40  import "github.com/mongodb/grip/level"
    41  
    42  func Log(l level.Priority, msg interface{}) {
    43  	std.Log(l, msg)
    44  }
    45  func Logf(l level.Priority, msg string, a ...interface{}) {
    46  	std.Logf(l, msg, a...)
    47  }
    48  func Logln(l level.Priority, a ...interface{}) {
    49  	std.Logln(l, a...)
    50  }
    51  func LogWhen(conditional bool, l level.Priority, m interface{}) {
    52  	std.LogWhen(conditional, l, m)
    53  }
    54  
    55  // Leveled Logging Methods
    56  // Emergency-level logging methods
    57  
    58  func EmergencyFatal(msg interface{}) {
    59  	std.EmergencyFatal(msg)
    60  }
    61  func Emergency(msg interface{}) {
    62  	std.Emergency(msg)
    63  }
    64  func Emergencyf(msg string, a ...interface{}) {
    65  	std.Emergencyf(msg, a...)
    66  }
    67  func Emergencyln(a ...interface{}) {
    68  	std.Emergencyln(a...)
    69  }
    70  func EmergencyPanic(msg interface{}) {
    71  	std.EmergencyPanic(msg)
    72  }
    73  func EmergencyWhen(conditional bool, m interface{}) {
    74  	std.EmergencyWhen(conditional, m)
    75  }
    76  
    77  // Alert-level logging methods
    78  
    79  func Alert(msg interface{}) {
    80  	std.Alert(msg)
    81  }
    82  func Alertf(msg string, a ...interface{}) {
    83  	std.Alertf(msg, a...)
    84  }
    85  func Alertln(a ...interface{}) {
    86  	std.Alertln(a...)
    87  }
    88  func AlertWhen(conditional bool, m interface{}) {
    89  	std.AlertWhen(conditional, m)
    90  }
    91  
    92  // Critical-level logging methods
    93  
    94  func Critical(msg interface{}) {
    95  	std.Critical(msg)
    96  }
    97  func Criticalf(msg string, a ...interface{}) {
    98  	std.Criticalf(msg, a...)
    99  }
   100  func Criticalln(a ...interface{}) {
   101  	std.Criticalln(a...)
   102  }
   103  func CriticalWhen(conditional bool, m interface{}) {
   104  	std.CriticalWhen(conditional, m)
   105  }
   106  
   107  // Error-level logging methods
   108  
   109  func Error(msg interface{}) {
   110  	std.Error(msg)
   111  }
   112  func Errorf(msg string, a ...interface{}) {
   113  	std.Errorf(msg, a...)
   114  }
   115  func Errorln(a ...interface{}) {
   116  	std.Errorln(a...)
   117  }
   118  func ErrorWhen(conditional bool, m interface{}) {
   119  	std.ErrorWhen(conditional, m)
   120  }
   121  
   122  // Warning-level logging methods
   123  
   124  func Warning(msg interface{}) {
   125  	std.Warning(msg)
   126  }
   127  func Warningf(msg string, a ...interface{}) {
   128  	std.Warningf(msg, a...)
   129  }
   130  func Warningln(a ...interface{}) {
   131  	std.Warningln(a...)
   132  }
   133  func WarningWhen(conditional bool, m interface{}) {
   134  	std.WarningWhen(conditional, m)
   135  }
   136  
   137  // Notice-level logging methods
   138  
   139  func Notice(msg interface{}) {
   140  	std.Notice(msg)
   141  }
   142  func Noticef(msg string, a ...interface{}) {
   143  	std.Noticef(msg, a...)
   144  }
   145  func Noticeln(a ...interface{}) {
   146  	std.Noticeln(a...)
   147  }
   148  func NoticeWhen(conditional bool, m interface{}) {
   149  	std.NoticeWhen(conditional, m)
   150  }
   151  
   152  // Info-level logging methods
   153  
   154  func Info(msg interface{}) {
   155  	std.Info(msg)
   156  }
   157  func Infof(msg string, a ...interface{}) {
   158  	std.Infof(msg, a...)
   159  }
   160  func Infoln(a ...interface{}) {
   161  	std.Infoln(a...)
   162  }
   163  func InfoWhen(conditional bool, message interface{}) {
   164  	std.InfoWhen(conditional, message)
   165  }
   166  
   167  // Debug-level logging methods
   168  
   169  func Debug(msg interface{}) {
   170  	std.Debug(msg)
   171  }
   172  func Debugf(msg string, a ...interface{}) {
   173  	std.Debugf(msg, a...)
   174  }
   175  func Debugln(a ...interface{}) {
   176  	std.Debugln(a...)
   177  }
   178  func DebugWhen(conditional bool, m interface{}) {
   179  	std.DebugWhen(conditional, m)
   180  }