Quick and dirty debugging output for tired Go programmers

q

CircleCI Go Report Card PkgGoDev

q is a better way to do print statement debugging.

Type q.Q instead of fmt.Printf and your variables will be printed like this:

q output examples

Why is this better than fmt.Printf?

  • Faster to type
  • Pretty-printed vars and expressions
  • Easier to see inside structs
  • Doesn't go to noisy-ass stdout. It goes to $TMPDIR/q.
  • Pretty colors!

Basic Usage

import "q"
...
q.Q(a, b, c)

For best results, dedicate a terminal to tailing $TMPDIR/q while you work.

Install

git clone https://github.com/ryboe/q $GOPATH/src/q

Put these functions in your shell config. Typing qq or rmqq will then start tailing $TMPDIR/q.

qq() {
    clear

    logpath="$TMPDIR/q"
    if [[ -z "$TMPDIR" ]]; then
        logpath="/tmp/q"
    fi

    if [[ ! -f "$logpath" ]]; then
        echo 'Q LOG' > "$logpath"
    fi

    tail -100f -- "$logpath"
}

rmqq() {
    logpath="$TMPDIR/q"
    if [[ -z "$TMPDIR" ]]; then
        logpath="/tmp/q"
    fi
    if [[ -f "$logpath" ]]; then
        rm "$logpath"
    fi
    qq
}

You also can simply tail -f $TMPDIR/q, but it's highly recommended to use the above commands.

Editor Integration

VS Code

Preferences > User Snippets > Go

"qq": {
    "prefix": "qq",
    "body": "q.Q($1) // DEBUG",
    "description": "Pretty-print to $TMPDIR/q"
}

Sublime Text

Tools > Developer > New Snippet

<snippet>
    <content><![CDATA[
q.Q($1) // DEBUG
]]></content>
    <tabTrigger>qq</tabTrigger>
    <scope>source.go</scope>
</snippet>

Atom

Atom > Open Your Snippets

'.source.go':
    'qq':
        'prefix': 'qq'
        'body': 'q.Q($1) // DEBUG'

JetBrains GoLand

Settings > Editor > Live Templates

In Go, add a new template with:

  • Abbreviation: qq
  • Description: Pretty-print to $TMPDIR/q
  • Template text: q.Q($END$) // DEBUG
  • Applicable in: select the Go scope

Emacs

Add a new snippet file to the go-mode snippets directory ($HOME/.emacs.d/snippets/go-mode/qq). This should contain:

# -*- mode: snippet -*-
# name: qq
# key: qq
# --
q.Q(${1:...}) // DEBUG

vim

TBD Send me a PR, please :)

Haven't I seen this somewhere before?

Python programmers will recognize this as a Golang port of the q module by zestyping.

Ping does a great job of explaining q in his awesome lightning talk from PyCon 2013. Watch it! It's funny :)

ping's PyCon 2013 lightning talk

FAQ

Why q.Q?

It's quick to type and unlikely to cause naming collisions.

Is q.Q() safe for concurrent use?

Yes.

Owner
Comments
  • defer Q() not printing output.

    defer Q() not printing output.

    package main
    
    import (
    	. "github.com/y0ssar1an/q"
    )
    
    func main() {
    	test()
    	Q("Third")
    }
    
    func test() {
    	defer Q("Second")
    	Q("First")
    }
    

    Produces output

    [18:49:47 qtest/main.go:14 main.test]
    0.000s First
    0.000s
    
    [18:49:47 qtest/main.go:9 main.main]
    0.000s Third
    

    Expected

    [18:49:47 qtest/main.go:14 main.test]
    0.000s First
    0.000s Second
    
    [18:49:47 qtest/main.go:9 main.main]
    0.000s Third
    
  • q explodes my go.mod

    q explodes my go.mod

    add Q to my project explodes my go.mod file with dependencies:

    I suspect most of these are linting dependencies. Would there be any way to not have these normally pulled in?

     require (
    +       github.com/OpenPeeDeeP/depguard v0.0.0-20181229194401-1f388ab2d810 // indirect
    +       github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect
            github.com/benbjohnson/genesis v0.2.1
            github.com/boltdb/bolt v1.3.1 // indirect
    +       github.com/coreos/etcd v3.3.11+incompatible // indirect
    +       github.com/fatih/color v1.7.0 // indirect
    +       github.com/go-lintpack/lintpack v0.5.2 // indirect
    +       github.com/go-ole/go-ole v1.2.2 // indirect
    +       github.com/go-toolsmith/astcast v1.0.0 // indirect
    +       github.com/go-toolsmith/astcopy v1.0.0 // indirect
    +       github.com/go-toolsmith/astfmt v1.0.0 // indirect
    +       github.com/go-toolsmith/astp v1.0.0 // indirect
    +       github.com/go-toolsmith/pkgload v1.0.0 // indirect
    +       github.com/go-toolsmith/typep v1.0.0 // indirect
    +       github.com/gogo/protobuf v1.2.0 // indirect
    +       github.com/golang/mock v1.2.0 // indirect
    +       github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6 // indirect
    +       github.com/golangci/gocyclo v0.0.0-20180528144436-0a533e8fa43d // indirect
    +       github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98 // indirect
    +       github.com/golangci/golangci-lint v1.12.5 // indirect
    +       github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219 // indirect
    +       github.com/golangci/revgrep v0.0.0-20180812185044-276a5c0a1039 // indirect
    +       github.com/golangci/tools v0.0.0-20190108095906-d95fd85c147a // indirect
    +       github.com/golangci/unparam v0.0.0-20180902115109-7ad9dbcccc16 // indirect
            github.com/gorilla/websocket v1.4.0
    +       github.com/kr/pty v1.1.3 // indirect
    +       github.com/mattn/go-isatty v0.0.4 // indirect
    +       github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d // indirect
    +       github.com/onsi/ginkgo v1.7.0 // indirect
    +       github.com/onsi/gomega v1.4.3 // indirect
    +       github.com/pkg/errors v0.8.1 // indirect
            github.com/pkg/term v0.0.0-20181116001808-27bbf2edb814
    +       github.com/shirou/gopsutil v2.18.12+incompatible // indirect
    +       github.com/shurcooL/go v0.0.0-20181215222900-0143a8f55f04 // indirect
    +       github.com/sirupsen/logrus v1.3.0 // indirect
    +       github.com/spf13/afero v1.2.0 // indirect
    +       github.com/spf13/cobra v0.0.3 // indirect
    +       github.com/spf13/viper v1.3.1 // indirect
    +       github.com/stretchr/testify v1.3.0 // indirect
            github.com/timshannon/bolthold v0.0.0-20180829183128-83840edea944
    +       github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 // indirect
    +       github.com/y0ssar1an/q v1.0.6 // indirect
            go.etcd.io/bbolt v1.3.0 // indirect
    -       golang.org/x/sys v0.0.0-20181206074257-70b957f3b65e // indirect
    +       golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc // indirect
    +       golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b
    +       golang.org/x/net v0.0.0-20190110200230-915654e7eabc // indirect
    +       golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
    +       golang.org/x/sys v0.0.0-20190109145017-48ac38b7c8cb // indirect
    +       golang.org/x/tools v0.0.0-20190111214448-fc1d57b08d7b // indirect
    +       gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
            periph.io/x/periph v3.4.0+incompatible
    +       sourcegraph.com/sourcegraph/go-diff v0.5.0 // indirect
    +       sourcegraph.com/sqs/pbtypes v1.0.0 // indirect
     )
    
  • Go1.13 build fix: go.mod: go1.12 => go1.13

    Go1.13 build fix: go.mod: go1.12 => go1.13

    Using go1.13.7 for building my project (that uses github.com/y0ssar1an/q as a dependency) I got the error:

    github.com/y0ssar1an/[email protected] requires
    github.com/golangci/[email protected] requires
    github.com/golangci/[email protected]: invalid version: unknown revision 2cefd77fef9b
    

    I've cloned the repository, made local changes in go.mod (just set up go1.13)

    index 86f936a..092e9a3 100644
    --- a/go.mod
    +++ b/go.mod
    @@ -1,5 +1,5 @@
     module github.com/y0ssar1an/q
    
    -go 1.12
    +go 1.13
    
     require github.com/kr/pretty v0.2.0
    (END)
    

    used the 'replace' in my project's go.mod (from github.com/y0ssar1an/q to local copy) - and that helped.

    At the same time, it works without any go.mod changes when I used go1.12.13 for the project build. Also, after making these go.mod changes I stay able to build the project using go1.12.

    It seems it could be better to use go1.13 in master to avoid problems like this one.

  • go build failed on go1.13+

    go build failed on go1.13+

    Using go1.13.7 for building my project (that uses github.com/y0ssar1an/q as a dependency) I got the error:

    github.com/y0ssar1an/[email protected] requires
    github.com/golangci/[email protected] requires
    github.com/golangci/[email protected]: invalid version: unknown revision 2cefd77fef9b
    

    I've cloned the repository, made local changes in go.mod (just set up go1.13)

    index 86f936a..092e9a3 100644
    --- a/go.mod
    +++ b/go.mod
    @@ -1,5 +1,5 @@
     module github.com/y0ssar1an/q
    
    -go 1.12
    +go 1.13
    
     require github.com/kr/pretty v0.2.0
    (END)
    

    used the 'replace' in my project's go.mod (from github.com/y0ssar1an/q to local copy) - and that helped.

    It seems it could be better to use go1.13 in master to avoid problems like this one.

  • use broken with go mod

    use broken with go mod

    When tryinq to use q in a project which uses go mod, any command run exits with an error. I am a little suspicious that the issue is really just a bad error message, but I don't quite see how it is getting triggered. Hopefully it make sense to you.

    Here is a very simple example that shows the issue.

    Create a dir with the following contents in main.go:

    // Package main provides an example of q/mod failure
    package main
    
    import "github.com/y0ssar1an/q"
    
    func main() {
    	i := 1
    	t := []int{1, 2, 3}
    	q.Q(i, t)
    }
    

    run go mod init github.com/reedobrien/w

    run go build and get the error:

    go: finding github.com/golangci/tools v0.0.0-20180902102414-2cefd77fef9b
    go: github.com/golangci/[email protected]: unknown revision 2cefd77fef9b
    

    I don't see golangci or tools in the q repo... so I suspect someone doing something clever vending dependencies, a bug in go mod, or both. Also I've been away from go for a bit and haven't used modules in anger before my current project. So I am a bit lost with them. Hopefully this rings a bell in your head.

  • argName: Handle *ast.Ident with nil Obj

    argName: Handle *ast.Ident with nil Obj

    Would panic in cases where the Obj for an Ident was nil. Not sure when this applies (in general) but one case was given in from a test file.

    Fixes #15

  • panic in prependArgName

    panic in prependArgName

    panic: runtime error: index out of range
    
    goroutine 1 [running]:
    github.com/y0ssar1an/q.prependArgName(0xc420403480, 0x2, 0x2, 0xc42043d0f0, 0x1, 0x1, 0x0, 0x0, 0x2)
    	/Users/ryan/go/src/github.com/y0ssar1an/q/helpers.go:156 +0x347
    github.com/y0ssar1an/q.Q(0xc4201206c0, 0x1, 0x1)
    	/Users/ryan/go/src/github.com/y0ssar1an/q/q.go:182 +0x20a
    github.com/apcera/apcera-setup/vendor/github.com/apcera/libretto/virtualmachine/azure/arm.(*VM).deploy(0xc420082340, 0xc4204b4350, 0x5)
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/vendor/github.com/apcera/libretto/virtualmachine/azure/arm/util.go:170 +0x30a
    github.com/apcera/apcera-setup/vendor/github.com/apcera/libretto/virtualmachine/azure/arm.(*VM).Provision(0xc420082340, 0xc420000180, 0x300000002)
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/vendor/github.com/apcera/libretto/virtualmachine/azure/arm/vm.go:135 +0xc1
    github.com/apcera/apcera-setup/commands/create.createVM(0xc42047e1e0, 0x1f, 0xc420120ca0)
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/commands/create/create.go:368 +0x54
    github.com/apcera/apcera-setup/commands/create.createBaseVMs(0xc42028e5a0, 0x3, 0x4, 0x1e49360, 0xc420470630, 0x1e49360, 0xc420470640)
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/commands/create/create.go:432 +0x4a3
    github.com/apcera/apcera-setup/commands/create.createVMs(0xc42028e5a0, 0x3, 0x4, 0xc4202c0240, 0x0, 0x0, 0x0)
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/commands/create/create.go:460 +0xad
    github.com/apcera/apcera-setup/commands/create.Run(0xc4202be480, 0x3c6a8f8, 0x0, 0x0, 0xc4202c0240, 0x0, 0x0)
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/commands/create/create.go:242 +0x675
    github.com/apcera/apcera-setup/commands.ConfiguredCommand.func1(0xc4202be480, 0x3c6a8f8, 0x0, 0x0)
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/commands/commands.go:111 +0x1b9
    github.com/apcera/apcera-setup/commands.UpdateCheck.func1(0xc4202be480, 0x3c6a8f8, 0x0, 0x0)
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/commands/commands.go:169 +0xe5
    github.com/apcera/apcera-setup/vendor/github.com/spf13/cobra.(*Command).execute(0xc4202be480, 0x3c6a8f8, 0x0, 0x0, 0xc4202be480, 0x3c6a8f8)
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/vendor/github.com/spf13/cobra/command.go:653 +0x2a2
    github.com/apcera/apcera-setup/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x3c41c20, 0x2210ef1, 0xb, 0xc420121f60)
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/vendor/github.com/spf13/cobra/command.go:728 +0x2fe
    main.main()
    	/Users/ryan/go/src/github.com/apcera/apcera-setup/apcera-setup.go:32 +0x38
    
  • Command qq and rmqq in the package wrote in Go

    Command qq and rmqq in the package wrote in Go

    Aliases are no longer needed. qq and rmqq are now install in $GOPATH/bin automatically.

    currently working on my free time on next feature:

    • --clear option to clear the screen when program is re-launch.
    • -f to select a logpath / file

    Hope you'll like it 👍 🍻

  • Should output String()

    Should output String()

    I see this:

    Render p.NodeType=hugolib.NodeType(3)
    

    NodeType is an int, but implements the Stringer interface, so I would expect the String() output to be in there somewhere.

  • Change pkg name from y0ssar1an/q to ryboe/q

    Change pkg name from y0ssar1an/q to ryboe/q

    Resolve #54. It's annoying to type y0ssar1an. Update README. Replace full github import with just import "q" Vendor github.com/kr/text, which go mod tidy wants now for some reason.

  • Switch from golang:1.12 to golang:1.12-alpine in GHA

    Switch from golang:1.12 to golang:1.12-alpine in GHA

    We don't need the full Debian-based golang container just to run tests. Using the smaller Alpine-based container will save a little time during CI. Note: This is only for GHA.

  • panic when q.Q() an empty *time.Time

    panic when q.Q() an empty *time.Time

    q.Q panic when have to print an empty *time.Time

    Version: v1.0.17 Steps to reproduce:

    var emptyDate *time.Time
    q.Q(emptyDate)
    

    Current result:

    emptyDate=%!v(PANIC=Format method: value method time.Time.GoString called using nil *Time pointer)
    

    Expected result

    emptyDate=(*time.Time)(nil)
    
  • add ability to also print to stdout

    add ability to also print to stdout

    this is really useful for CLi apps also.

    so when i do q.Q(variable), it also prints out to the STDout

    I coudl tail the temp log, but then i loose control of intermixing. for example i want everything to go to tmp log but only some things to go to stdout. I sort of started to use this for nice formatting

    https://github.com/olekukonko/tablewriter

A simple to use log system, minimalist but with features for debugging and differentiation of messages
A simple to use log system, minimalist but with features for debugging and differentiation of messages

A simple to use log system, minimalist but with features for debugging and differentiation of messages

Sep 26, 2022
Implements a deep pretty printer for Go data structures to aid in debugging

go-spew Go-spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is

Jan 9, 2023
Implements a deep pretty printer for Go data structures to aid in debugging

spew Spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is provi

Dec 25, 2022
Peimports - based on golang's debug/pe this package gives quick access to the ordered imports of pe files with ordinal support

This code is almost entirely derived from the Go standard library's debug/pe package. It didn't provide access to ordinal based entries in the IAT and

Jan 5, 2022
A customized GORM logger that implements the appropriate interface and uses Logrus to output logs

CryptoMath GORM Logger A customized GORM logger that implements the appropriate interface and uses Logrus to output logs. Install go get github.com/ma

Nov 6, 2021
This package enables json output, level logging and so on to standard go logger.

logplug This package enables json output, level logging and so on to standard logger. Usage log.SetOutput(logplug.NewJSONPlug(os.Stderr, logplug.LogF

Dec 27, 2021
Gomol is a library for structured, multiple-output logging for Go with extensible logging outputs

gomol Gomol (Go Multi-Output Logger) is an MIT-licensed structured logging library for Go. Gomol grew from a desire to have a structured logging libra

Sep 26, 2022
Yandex Cloud Logging output for Fluent Bit

Fluent Bit plugin for Yandex Cloud Logging Fluent Bit output for Yandex Cloud Logging. Configuration parameters Key Description group_id (optional) Lo

Nov 17, 2022
Secure logger in Go to avoid output sensitive data in log
Secure logger in Go to avoid output sensitive data in log

zlog A main distinct feature of zlog is secure logging that avoid to output secret/sensitive values to log. The feature reduce risk to store secret va

Dec 6, 2022
Monitor pipe progress via output to standard error.

Pipe Monitor Monitor pipe progress via output to standard error. Similar to functionality provided by the Pipe Viewer (pv) command, except this comman

Nov 14, 2022
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.

The open-source platform for monitoring and observability. Grafana allows you to query, visualize, alert on and understand your metrics no matter wher

Jan 3, 2023
Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.
Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.

Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.

Nov 10, 2022
Simple and configurable Logging in Go, with level, formatters and writers

go-log Logging package similar to log4j for the Golang. Support dynamic log level Support customized formatter TextFormatter JSONFormatter Support mul

Sep 26, 2022
A Go (golang) package providing high-performance asynchronous logging, message filtering by severity and category, and multiple message targets.

ozzo-log Other languages 简体中文 Русский Description ozzo-log is a Go package providing enhanced logging support for Go programs. It has the following fe

Dec 17, 2022
Library and program to parse and forward HAProxy logs

haminer Library and program to parse and forward HAProxy logs. Supported forwarder, Influxdb Requirements Go for building from source code git for dow

Aug 17, 2022
Cloudinsight Agent is a system tool that monitors system processes and services, and sends information back to your Cloudinsight account.

Cloudinsight Agent 中文版 README Cloudinsight Agent is written in Go for collecting metrics from the system it's running on, or from other services, and

Nov 3, 2022
Distributed simple and robust release management and monitoring system.
Distributed simple and robust release management and monitoring system.

Agente Distributed simple and robust release management and monitoring system. **This project on going work. Road map Core system First worker agent M

Nov 17, 2022
List files and their creation, modification and access time on android

andfind List files and their access, modification and creation date on a Android

Jan 5, 2022
Every 10 minutes, memory, cpu and storage usage is checked and if they over 80%, sending alert via email.

linux-alert Every 10 minutes, memory, cpu and storage usage is checked and if they over 80%, sending alert via email. Usage Create .env file from .env

Feb 6, 2022