An opinionated package that helps you print user-friendly output messages from your Go command line applications.

github.com/eth-p/clout

(Command Line Output)

clout is a package that helps you print user-friendly output messages from your Go command line applications.

Installation

import (
    "github.com/eth-p/clout"
)

Why clout?

Clout helps you print readable and consistent messages using a familiar klog-like API. It's unobtrusive, and designed to enable you to write command line tools without having to worry about the specifics of ANSI colors or stdout/stderr best practices.

Messages Types

Instead of asking you to figure out which output stream a message should be destined for, clout provides with you different types of messages that you can print:

Constant Usage
Status An update to the program's current status.
Info An informational message.
Warning A warning about a potential issue.
Deprecation A warning about a feature which will be removed or unsupported in the future.
Error A severe error.

By default, clout will direct these messages into an appropriate output stream. Warning and error messages will go to the standard error, and all other messages will go to the standard output.

Configurable Verbosity

Just like klog, clout supports different verbosity levels. If you want to provide extra debug information without littering the code with if-statements, you can do that:

clout.V(2).Infof("Processing %s", file)            // Visible by default.
clout.V(4).Statusf("%s: Unmarshalling yaml", file) // Only visible with verbosity 4 or higher.

Best Practices

The following table shows the best practices for using verbosity levels. It's based on the Kubernetes logging best practices:

Level For
V(0) Programmer errors, logging extra info about a panic, cli argument handling.
V(1) Information about config, errors.
V(2) System state, log messages.
V(3) Extended info about system state changes.
V(4) Logging in "thorny parts of code".
V(5) Trace level verbosity.

Color Support

When your terminal supports colors, giant walls of plain text can be unwieldy. clout helps you with that by providing color support (Linux/MacOS only) with no extra burden on you:

  • Warning messages will be prefixed with "warning: " and automatically colored yellow.
  • Deprecation messages will be prefixed with "deprecated: " and automatically colored yellow.
  • Error messages will be prefixed with "error: " and automatically colored red.

And if you have any text that you feel should be highlighted to stand out (e.g. paths)? You can simply wrap parameters in a Highlight, and clout will handle it.

Conditional Colors

Best of all, colors are enabled conditionally. If someone pipes your command's output, colors will be disabled automatically. clout even supports the NO_COLOR standard ;)

Example

import (
    "github.com/eth-p/clout"
    "github.com/eth-p/clout/pkg/highlight"
)

func main() {
    clout.V(2).Infof("Initializing application...")
    // -> Initializing application...
    
    clout.V(3).Info("Args: %#v", os.Args)
    // This won't print anything, because the default verbosity is level 2.
	
    if len(os.Args) != 2 {
        clout.V(1).Error("not enough arguments")
        // -> error: not enough arguments
        return
    }
    
    clout.V(2).Infof("Hello, %s.", highlight.Cyan(os.Args[1]))
    // -> Hello, SOME_EXECUTABLE_NAME
    // On supported systems, SOME_EXECUTABLE_NAME will be cyan.
}

For more detailed examples, feel free to check out the example directory.

License

MIT License

Owner
Ethan P.
A software engineering student.
Ethan P.
Similar Resources

replicate messages from streaming channel to jetstream

NATS Streaming/Jetstream Replicator [SJR] Introduction This project replicates messages from streaming channels to jetstream. but why? At Snapp when w

Dec 15, 2022

Kafka tool to emit tombstones for messages based on header value matches

Langolier Langolier is a CLI tool to consume a Kafka topic and emit tombstones for messages matched by header name/value pairs. Usage Usage of langoli

Sep 22, 2021

Service responsible for streaming Kafka messages.

kafka-stream 🧙🏼‍♂️ Service responsible for streaming Kafka messages. What it does? This service reads all messages from the input topic and sends th

Oct 16, 2021

Batch messages over a time interval

timebatch timebatch is a package for batching messages over a time interval. This can be useful for receiving messages that occur "quickly" and sendin

Nov 3, 2021

Send messages to icq-chatid when new order arrive

Получить номер последнего заказа, способ оплаты, способ доставки SELECT virtuemart_order_id FROM ce7l3_virtuemart_orders ORDER BY virtuemart_order_id

Dec 22, 2021

Go library for dealing with Ademco and Contact-ID messages

Ademco For Go A lightweight golang library for dealing with Contact-ID and Ademco messaging formats. Installation install via go get $ go get github.c

Jan 11, 2022

Korero - Send, recieve and manage messages on multiple platforms

Korero: Send, recieve and manage messages on multiple platforms Korero is a term

Jun 22, 2022

CLI tool for generating random messages with rules & publishing to the cloud services (SQS,SNS,PUB/SUB and etc.)

Randomsg A CLI tool to generate random messages and publish to cloud services like (SQS,SNS,PUB/SUB and etc.). TODO Generation of nested objects is no

Sep 22, 2022

Chanify is a safe and simple notification tools. This repository is command line tools for Chanify.

Chanify is a safe and simple notification tools. For developers, system administrators, and everyone can push notifications with API.

Dec 29, 2022
Related tags
A basic presence tracker, that sends messages when the provided user's presence changed, written with discordgo

presenceTracker A basic presence tracker, that sends messages when the provided user's presence changed, written with discordgo Just put the User ID t

Oct 12, 2022
Open source Observability Platform. 👉 SigNoz helps developers find issues in their deployed applications & solve them quickly
Open source Observability Platform. 👉 SigNoz helps developers find issues in their deployed applications & solve them quickly

SigNoz SigNoz is an opensource observability platform. SigNoz uses distributed tracing to gain visibility into your systems and powers data using Kafk

Jan 4, 2023
Kudruk helps you to create queue channels and manage them gracefully.

kudruk Channels are widely used as queues. kudruk (means queue in Turkish) helps you to easily create queue with channel and manage the data in the qu

Feb 21, 2022
Chanman helps you to create queue channels and manage them gracefully.

chanman Channels are widely used as queues. chanman (Channel Manager) helps you to easily create queue with channel and manage the data in the queue.

Oct 16, 2021
An extremely opinionated TypeScript monorepo tool.

Unirepo Unirepo is an extremely opinionated TypeScript build tool. Typical monorepo management tools in the Node.js ecosystem provide automation aroun

Nov 29, 2022
A little opinionated program to automatically provision my Aerohive APs without HiveManager/ExtremeCloud IQ

Aerohive Provision A little opinionated program to automatically provision my Aerohive APs without HiveManager/ExtremeCloud IQ. Unfortunately a lot of

Nov 28, 2022
graylog-golang is a full implementation for sending messages in GELF (Graylog Extended Log Format) from Go (Golang) to Graylog

graylog-golang is a full implementation for sending messages in GELF (Graylog Extended Log Format) from Go (Golang) to Graylog

Dec 5, 2022
RapidMQ is a pure, extremely productive, lightweight and reliable library for managing of the local messages queue

RapidMQ RapidMQ is a pure, extremely productive, lightweight and reliable library for managing of the local messages queue in the Go programming langu

Sep 27, 2022
Apache Kafka Web UI for exploring messages, consumers, configurations and more with a focus on a good UI & UX.
Apache Kafka Web UI for exploring messages, consumers, configurations and more with a focus on a good UI & UX.

Kowl - Apache Kafka Web UI Kowl (previously known as Kafka Owl) is a web application that helps you to explore messages in your Apache Kafka cluster a

Jan 3, 2023
A script written to automatically send whatsapp messages

whatsapp-auto-message A script written to automatically send whatsapp messages Config Dosyasını Ayarlama { "numbers": "phone_numbers.txt", "sleep": 2,

Jul 21, 2022