Skip to content

julianfrank/console

Repository files navigation

GoDoc Coverage Status Build Status Go Report Card Gitter

console package for those used to JS console.log(...)

Simple Console Log Package useful for anyone coming from Javascript background

Usage

Just import this package

import "github.com/julianfrank/console"

Log

In your Application use the familiar console.Log ...Just remember that the L is capital

comment:="Awsome!"
dude:="Julian Frank"
console.Log("This comment (%s) was made by %s",comment,dude)

mylog:=console.Log("This comment (%s) was made by %s",comment,dude)
//Output mylog=> "This comment (Awsome!) was made by Julian Frank"

Error

In your Application use the familiar console.Error ...Just remember that the E is capital

comment:="Awsome!"
dude:="Julian Frank"
myError:=console.Error("This comment (%s) was made by %s")
//Output myError=> "This comment (Awsome!) was made by Julian Frank" 
//of type error
//Use err.Error() to retreive error string 

Timed

This tries to replicate what the console timestart/timeend does in JS... it is slightly different... here you will need to record the start time in a variable at the point where you want to start measuring... in the point were you need the measure use console.Timed(,,the variables) The elabpsed time will be automatically appended to the pattern with a tab

ts:=time.Now()
console.TimedMode=true
comment:="Awsome!"
dude:="Julian Frank"
console.Timed(ts,"This comment (%s) was made by %s",comment,dude)

mylog:=console.Log(ts,"This comment (%s) was made by %s",comment,dude)
//Output mylog=> "This comment (Awsome!) was made by Julian Frank    0s"

Console Display Flags

If You want to selectively enable or disable console display of Log or Error you can simply do that by setting console.LogMode and console.ErrorMode to true or false. True is default

//To make screen completely quiet
console.LogMode=false
console.ErrorMode=false
console.TimedMode=false
//To Display only errors and not the Logs
console.LogMode=false
console.ErrorMode=true
console.TimedMode=false

License

Apache 2.0

Releases

No releases published

Packages

No packages published

Languages