github.com/iDigitalFlame/xmt@v0.5.4/c2/cout/v_no_implant.go (about)

     1  //go:build !implant
     2  // +build !implant
     3  
     4  // Copyright (C) 2020 - 2023 iDigitalFlame
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    18  //
    19  
    20  // Package cout is a simple log handling solution for the c2 package.
    21  // This is used internally to create loggers and to disable logging if needed,
    22  // such as the "client" built tag being used.
    23  package cout
    24  
    25  import "github.com/PurpleSec/logx"
    26  
    27  // Enabled is a compile time constant that can be used to disable/enable the
    28  // logx Logger and prevent any un-needed fmt calls as the client does not
    29  // /naturally/ need to produce output.
    30  //
    31  // Only needed for debug purposes.
    32  const Enabled = true
    33  
    34  // Log is an interface for any type of struct that supports standard Logging
    35  // functions.
    36  type Log struct {
    37  	_ [0]func()
    38  	logx.Log
    39  }
    40  
    41  // New creates a Log instance from a logx Logger.
    42  func New(l logx.Log) Log {
    43  	return Log{Log: l}
    44  }
    45  
    46  // Set updates the internal logger. This function is a NOP if the logger is nil
    47  // or logging is not enabled via the 'client' build tag.
    48  func (l *Log) Set(v logx.Log) {
    49  	if l == nil {
    50  		return
    51  	}
    52  	l.Log = v
    53  }
    54  
    55  // Info writes an informational message to the logger.
    56  // The function arguments are similar to fmt.Sprintf and fmt.Printf. The first argument is
    57  // a string that can contain formatting characters. The second argument is a vardict of
    58  // interfaces that can be omitted or used in the supplied format string.
    59  func (l Log) Info(s string, v ...interface{}) {
    60  	if l.Log == nil {
    61  		return
    62  	}
    63  	l.Log.Info(s, v...)
    64  }
    65  
    66  // Error writes an error message to the logger.
    67  // The function arguments are similar to fmt.Sprintf and fmt.Printf. The first argument is
    68  // a string that can contain formatting characters. The second argument is a vardict of
    69  // interfaces that can be omitted or used in the supplied format string.
    70  func (l Log) Error(s string, v ...interface{}) {
    71  	if l.Log == nil {
    72  		return
    73  	}
    74  	l.Log.Error(s, v...)
    75  }
    76  
    77  // Trace writes a tracing message to the logger.
    78  // The function arguments are similar to fmt.Sprintf and fmt.Printf. The first argument is
    79  // a string that can contain formatting characters. The second argument is a vardict of
    80  // interfaces that can be omitted or used in the supplied format string.
    81  func (l Log) Trace(s string, v ...interface{}) {
    82  	if l.Log == nil {
    83  		return
    84  	}
    85  	l.Log.Trace(s, v...)
    86  }
    87  
    88  // Debug writes a debugging message to the logger.
    89  // The function arguments are similar to fmt.Sprintf and fmt.Printf. The first argument is
    90  // a string that can contain formatting characters. The second argument is a vardict of
    91  // interfaces that can be omitted or used in the supplied format string.
    92  func (l Log) Debug(s string, v ...interface{}) {
    93  	if l.Log == nil {
    94  		return
    95  	}
    96  	l.Log.Debug(s, v...)
    97  }
    98  
    99  // Warning writes a warning message to the logger.
   100  // The function arguments are similar to fmt.Sprintf and fmt.Printf. The first argument is
   101  // a string that can contain formatting characters. The second argument is a vardict of
   102  // interfaces that can be omitted or used in the supplied format string.
   103  func (l Log) Warning(s string, v ...interface{}) {
   104  	if l.Log == nil {
   105  		return
   106  	}
   107  	l.Log.Warning(s, v...)
   108  }