github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/agent/clib/logging.go (about)

     1  package main
     2  
     3  import (
     4  	"C"
     5  	"fmt"
     6  	logger2 "github.com/pyroscope-io/pyroscope/pkg/agent/log"
     7  )
     8  
     9  //export TestLogger
    10  func TestLogger() int {
    11  	logger.Errorf("logger test error %d", 123)
    12  	logger.Infof("logger test info %d", 123)
    13  	logger.Debugf("logger test debug %d", 123)
    14  	return 0
    15  }
    16  
    17  //export SetLoggerLevel
    18  func SetLoggerLevel(l int) int {
    19  	level = l
    20  	return 0
    21  }
    22  
    23  var logger logger2.Logger
    24  var level int
    25  
    26  func init() {
    27  	logger = &clibLogger{}
    28  }
    29  
    30  type clibLogger struct{}
    31  
    32  func (*clibLogger) Errorf(a string, b ...interface{}) {
    33  	if level < 0 {
    34  		return
    35  	}
    36  	if a[len(a)-1] != '\n' {
    37  		a += "\n"
    38  	}
    39  	fmt.Printf("[ERROR] "+a, b...)
    40  }
    41  
    42  func (*clibLogger) Infof(a string, b ...interface{}) {
    43  	if level < 1 {
    44  		return
    45  	}
    46  	if a[len(a)-1] != '\n' {
    47  		a += "\n"
    48  	}
    49  	fmt.Printf("[INFO] "+a, b...)
    50  }
    51  
    52  func (*clibLogger) Debugf(a string, b ...interface{}) {
    53  	if level < 2 {
    54  		return
    55  	}
    56  	if a[len(a)-1] != '\n' {
    57  		a += "\n"
    58  	}
    59  	fmt.Printf("[DEBUG] "+a, b...)
    60  }