github.com/DataDog/datadog-agent/pkg/security/secl@v0.55.0-devel.0.20240517055856-10c4965fea94/log/logger.go (about)

     1  // Unless explicitly stated otherwise all files in this repository are licensed
     2  // under the Apache License Version 2.0.
     3  // This product includes software developed at Datadog (https://www.datadoghq.com/).
     4  // Copyright 2016-present Datadog, Inc.
     5  
     6  // Package log holds log related files
     7  package log
     8  
     9  // Logger interface used to remove the dependency of this package to the logger of the agent
    10  type Logger interface {
    11  	// Infof is used to print a info level log
    12  	Infof(format string, params ...interface{})
    13  	// Tracef is used to print a trace level log
    14  	Tracef(format string, params ...interface{})
    15  	// Debugf is used to print a trace level log
    16  	Debugf(format string, params ...interface{})
    17  	// Errorf is used to print an error
    18  	Errorf(format string, params ...interface{})
    19  
    20  	IsTracing() bool
    21  }
    22  
    23  // NullLogger is a default implementation of the Logger interface
    24  type NullLogger struct{}
    25  
    26  // Tracef is used to print a trace level log
    27  func (l NullLogger) Tracef(_ string, _ ...interface{}) {
    28  }
    29  
    30  // Debugf is used to print a trace level log
    31  func (l NullLogger) Debugf(_ string, _ ...interface{}) {
    32  }
    33  
    34  // Errorf is used to print an error
    35  func (l NullLogger) Errorf(_ string, _ ...interface{}) {
    36  }
    37  
    38  // Infof is used to print an info
    39  func (l NullLogger) Infof(_ string, _ ...interface{}) {
    40  }
    41  
    42  // IsTracing is used to check if TraceF would actually log
    43  func (l NullLogger) IsTracing() bool {
    44  	return false
    45  }
    46  
    47  // OrNullLogger ensures that the provided logger is non-nil by returning a NullLogger if it is
    48  func OrNullLogger(potential Logger) Logger {
    49  	if potential != nil {
    50  		return potential
    51  	}
    52  	return &NullLogger{}
    53  }