github.com/laevusdexter/asmcgocall@v0.0.0-20200220061330-f484a47e9b97/log.go (about)

     1  package asmcgocall
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  var Debug bool = false
     9  
    10  func bytes(i interface{}) string {
    11  	var res int
    12  
    13  	switch i.(type) {
    14  	case int:
    15  		res = i.(int)
    16  	case uintptr:
    17  		res = int(i.(uintptr))
    18  	}
    19  
    20  	if res > 1 {
    21  		return "bytes"
    22  	} else {
    23  		return "byte"
    24  	}
    25  }
    26  
    27  type LogFormat byte
    28  
    29  const (
    30  	LogFormatDefault = iota
    31  	LogFormatC
    32  	LogFormatGo
    33  )
    34  
    35  var logFormat LogFormat = LogFormatC
    36  
    37  func SetLogFormat(logf LogFormat) {
    38  	logFormat = logf
    39  }
    40  
    41  func logf(str string, args ...interface{}) {
    42  	switch logFormat {
    43  	case LogFormatC:
    44  		if strings.Index(str, "__pad") != -1 {
    45  			return
    46  		}
    47  
    48  		for i, a := range args {
    49  			switch a.(type) {
    50  			case string:
    51  				args[i] = strings.ReplaceAll(args[i].(string), "_Ctype_", "")
    52  			}
    53  		}
    54  	case LogFormatGo:
    55  		if strings.Index(str, "__pad") != -1 {
    56  			return
    57  		}
    58  
    59  		for i, a := range args {
    60  			switch a.(type) {
    61  			case string:
    62  				args[i] = strings.ReplaceAll(args[i].(string), "_Ctype_", "C.")
    63  			}
    64  		}
    65  	}
    66  
    67  	fmt.Printf(str, args...)
    68  }