github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/internal/logger/level.go (about)

     1  // Copyright (C) MongoDB, Inc. 2023-present.
     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. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     6  
     7  package logger
     8  
     9  import "strings"
    10  
    11  // DiffToInfo is the number of levels in the Go Driver that come before the
    12  // "Info" level. This should ensure that "Info" is the 0th level passed to the
    13  // sink.
    14  const DiffToInfo = 1
    15  
    16  // Level is an enumeration representing the log severity levels supported by
    17  // the driver. The order of the logging levels is important. The driver expects
    18  // that a user will likely use the "logr" package to create a LogSink, which
    19  // defaults InfoLevel as 0. Any additions to the Level enumeration before the
    20  // InfoLevel will need to also update the "diffToInfo" constant.
    21  type Level int
    22  
    23  const (
    24  	// LevelOff suppresses logging.
    25  	LevelOff Level = iota
    26  
    27  	// LevelInfo enables logging of informational messages. These logs are
    28  	// high-level information about normal driver behavior.
    29  	LevelInfo
    30  
    31  	// LevelDebug enables logging of debug messages. These logs can be
    32  	// voluminous and are intended for detailed information that may be
    33  	// helpful when debugging an application.
    34  	LevelDebug
    35  )
    36  
    37  const (
    38  	levelLiteralOff       = "off"
    39  	levelLiteralEmergency = "emergency"
    40  	levelLiteralAlert     = "alert"
    41  	levelLiteralCritical  = "critical"
    42  	levelLiteralError     = "error"
    43  	levelLiteralWarning   = "warning"
    44  	levelLiteralNotice    = "notice"
    45  	levelLiteralInfo      = "info"
    46  	levelLiteralDebug     = "debug"
    47  	levelLiteralTrace     = "trace"
    48  )
    49  
    50  var LevelLiteralMap = map[string]Level{
    51  	levelLiteralOff:       LevelOff,
    52  	levelLiteralEmergency: LevelInfo,
    53  	levelLiteralAlert:     LevelInfo,
    54  	levelLiteralCritical:  LevelInfo,
    55  	levelLiteralError:     LevelInfo,
    56  	levelLiteralWarning:   LevelInfo,
    57  	levelLiteralNotice:    LevelInfo,
    58  	levelLiteralInfo:      LevelInfo,
    59  	levelLiteralDebug:     LevelDebug,
    60  	levelLiteralTrace:     LevelDebug,
    61  }
    62  
    63  // ParseLevel will check if the given string is a valid environment variable
    64  // for a logging severity level. If it is, then it will return the associated
    65  // driver's Level. The default Level is “LevelOff”.
    66  func ParseLevel(str string) Level {
    67  	for literal, level := range LevelLiteralMap {
    68  		if strings.EqualFold(literal, str) {
    69  			return level
    70  		}
    71  	}
    72  
    73  	return LevelOff
    74  }