dbgo

package module
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: BSD-3-Clause Imports: 10 Imported by: 60

README

godebug

license

Small library of tools for debugging Go (golang) programs.

The most useful of these is LF(). It returns a line number and file name. The parameter is an optional number. 1 indicates that you want it for the current call. 2 would be the parent of the current call.

Example:


	package main

	import (
		"fmt"

		"git.q8s.co/pschlump/dbgo"
	)

	func main() {
		dbgo.Printf("I am at: %(LF), data %(J)\n", []string{1,2,3})
	}

LF() takes an optional parameter, 1 indicates the current function, 2 is the parent, 3 the grandparent.

I will add complete documentation tomorrow.

Formats:

Format Description
%(LF) print out line number
%(j) convert data using json.Encode and output with indentation
%(J) convert data using json.Encode and output

ChkEnv

Return true if the passed environment variable can be parsed to be a true value. Values are cached so that the os.Getenv is only called once for each variable.

There is a test in ./test/test.sh to test this (or use the Makefile).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ColorBlack string

Black

View Source
var ColorBlue string

Blue

View Source
var ColorBlueOnWhite string
View Source
var ColorCyan string

Cyan

View Source
var ColorGreen string

Green

View Source
var ColorGreenOnWhite string
View Source
var ColorMagenta string

Magenta

View Source
var ColorMagentaOnWhite string
View Source
var ColorRed string

Red

View Source
var ColorReset string

Reset to default color

View Source
var ColorTab map[string]string
View Source
var ColorWhiteOnBlue string
View Source
var ColorYellow string

Yellow

Functions

func BackTickQuote

func BackTickQuote(ss string) string

func ChkEnv

func ChkEnv(envVar string) bool

func Db2Printf

func Db2Printf(flag bool, format string, a ...interface{}) (n int, err error)

Printf with a true false flag.

func DbFpf

func DbFpf(db bool, w io.Writer, format string, a ...interface{}) (n int, err error)

func DbFprintf

func DbFprintf(dbflag string, w io.Writer, format string, a ...interface{}) (n int, err error)

func DbPf

func DbPf(db bool, format string, a ...interface{}) (n int, err error)

func DbPfb

func DbPfb(db bool, format string, a ...interface{}) (n int, err error)

func DbPfe

func DbPfe(envVar string, format string, a ...interface{}) (n int, err error)

func DbPrintf

func DbPrintf(dbflag string, format string, a ...interface{}) (n int, err error)

func FILE

func FILE(d ...int) string

FILE Returns the current file name.

func FUNCNAME

func FUNCNAME(d ...int) string

FUNCNAME returns the current function name as a string.

func Fprintf

func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

func IAmAt

func IAmAt(s ...string)

IAmAt print out the current Function,File,Line No and an optional set of strings.

func IAmAt2

func IAmAt2(s ...string)

IAmAt2 prints out the current Function,File,Line No and an optional set of strings - do this for 2 levels deep.

func InArray

func InArray(s string, arr []string) int

InArray returns the subscript if the string 's' is found in the array 'arr', else -1

func InArrayInt

func InArrayInt(s int, arr []int) int

Return 0..n if 'n' is in the array arr, else -1.

func InArrayString

func InArrayString(s string, arr []string) int

Return 0..n if 's' is in the array arr, else -1.

func IsDbOn

func IsDbOn(dbflag string) bool

func LF

func LF(d ...int) string

LF Returns the File name and Line no as a string.

func LF2

func LF2(d ...int) (line int, file string)

LF2 returns the line/file for the parent.

func LFj

func LFj(d ...int) string

LFj returns the File name and Line no as a string. - for JSON as string

func LINE

func LINE(d ...int) string

LINE Return the current line number as a string. Default parameter is 1, must be an integer That reflects the depth in the call stack. A value of 0 would be the LINE() function itself. If you supply more than one parameter, 2..n are ignored.

func LINEnf

func LINEnf(d ...int) (int, string)

LINEnf Returns line number, 0 if error

func ParseBool

func ParseBool(s string) (b bool)

func Printf

func Printf(format string, a ...interface{}) (n int, err error)

func ProcessFormat

func ProcessFormat(format string, a []interface{}) (rv string, params []interface{})

func SVar

func SVar(v interface{}) string

SVar return the JSON encoded version of the data.

func SVarI

func SVarI(v interface{}) string

SVarI return the JSON encoded version of the data with tab indentation.

func SetDbFlag

func SetDbFlag(f map[string]bool)

func SetFlag

func SetFlag(name, sValue string)

func Sprintf

func Sprintf(format string, a ...interface{}) (ss string)

func StdErrPiped

func StdErrPiped() bool

StdErrPiped returns true if os.Stderr apears to be send to a pipe

func StdInPiped

func StdInPiped() bool

StdErrPiped returns true if os.Stdin apears to be send to a pipe

func StdOutPiped

func StdOutPiped() bool

StdErrPiped returns true if os.Stdout apears to be send to a pipe

func TrIAmAt

func TrIAmAt(s ...string)

Hm...

Types

type LogData

type LogData interface {
	// Setup
	OutputDestination(FilePtr io.Writer, isTerminal bool) // Output destinations are collected
	StatusCode(code int)                                  // 404 etc.
	ErrorMessageFormat()                                  // Set an error message format, text/plain, html, application/json etc.

	// Message
	OutputDestinationWeb()                      // per call output destination.
	Severity(x LogSeverity)                     //
	Depth(d int)                                // Default to -1, for normal LF but can be set.
	MessageQuery(s string, data ...interface{}) // SQL query if applicable.
	MessageData(s string, data ...interface{})  // Bind variables
	Message(s string, data ...interface{})      // fmt.Printf format, followed by items, %! - set to secret for next item.
	UserMessage(s string, data ...interface{})  // fmt.Printf format, followed by items

	// Finalize
	Send() // Completed Log Message
}

func NewLogDataFile

func NewLogDataFile(fn string) (rv LogData)

type LogDataIntermediate

type LogDataIntermediate struct {
	LineNo int
}

type LogSeverity

type LogSeverity int

type LogToFile

type LogToFile struct {
	LineNo int
	Files  []*os.File
}

func (*LogToFile) Depth

func (lf *LogToFile) Depth(d int)

func (*LogToFile) ErrorMessageFormat

func (lf *LogToFile) ErrorMessageFormat()

func (*LogToFile) Message

func (lf *LogToFile) Message(s string, data ...interface{})

func (*LogToFile) MessageData

func (lf *LogToFile) MessageData(s string, data ...interface{})

func (*LogToFile) MessageQuery

func (lf *LogToFile) MessageQuery(s string, data ...interface{})

func (*LogToFile) OutputDestination

func (lf *LogToFile) OutputDestination(FilePtr io.Writer, isTerminal bool)

func (*LogToFile) OutputDestinationWeb

func (lf *LogToFile) OutputDestinationWeb()

Message

func (*LogToFile) Send

func (lf *LogToFile) Send()

Finalize

func (*LogToFile) Severity

func (lf *LogToFile) Severity(x LogSeverity)

func (*LogToFile) StatusCode

func (lf *LogToFile) StatusCode(code int)

func (*LogToFile) UserMessage

func (lf *LogToFile) UserMessage(s string, data ...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL