prefix

package module
v1.7.2-0...-2a5a752 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0, MIT Imports: 7 Imported by: 0

README ΒΆ

prefix

πŸ”΄ prepend numbers, stats, dates, durations to streams

go.dev reference License GitHub release Docker Metrics Made by Manfred Touron

Go Release PR GolangCI codecov Go Report Card CodeFactor

Usage

foo@bar:~$ prefix -h
USAGE
  prefix [flags] file

FLAGS
  -format string
    	format string (default "{{DEFAULT}} ")

SYNTAX
  {{.Duration | short_duration}}      {{.Duration}} displayed in a pretty & short format (len<=7)
  {{.Duration}}                       time since previous line was started
  {{.Format}}                         the value you set with -format
  {{.LineNumber3}}                    alias for {{printf "%-3d" .LineNumber}}
  {{.LineNumber4}}                    alias for {{printf "%-4d" .LineNumber}}
  {{.LineNumber5}}                    alias for {{printf "%-5d" .LineNumber}}
  {{.LineNumber}}                     display line number
  {{.ShortDuration}}                  alias for {{.Duration | short_duration}}
  {{.ShortUptime}}                    alias for {{.Uptime | short_duration}}
  {{.Uptime | short_duration}}        {{.Uptime}} displayed in a pretty & short format (len<=7)
  {{.Uptime}}                         time since the the prefixer was initialized
  {{env "USER"}}                      replace with content of the $USER env var
  {{now | unixEpoch}}                 current timestamp
  {{now}}                             current date (format: 2006-01-02 15:04:05.999999999 -0700 MST)
  {{uuidv4}}                          UUID of the v4 (randomly generated) type

  the following helpers are also available:
  - from the text/template library    https://golang.org/pkg/text/template/
  - from the sprig project            https://github.com/masterminds/sprig#usage

PRESETS
  {{DEFAULT}}          {{.LineNumber3}} up={{.ShortUptime}} d={{.ShortDuration}} |
  {{SHORT_DATE}}       {{now | date "06/02/01 15:04:05"}}
  {{SLOW_LINES}}       {{if (gt .Duration 1000000000)}}SLOW{{else}}    {{end}} {{.Duration | short_duration}} 

EXAMPLES
  prefix apache.log
  prefix -format=">>>" apache.log
  tail -f apache.log | prefix -
  my-cool-program 2>&1 | prefix -format="#{{.LineNumber5}} " -
foo@bar:~$ generate-fake-data | prefix -format="#{{.LineNumber3}} {{.ShortUptime}} {{.ShortDuration}} | "
#1   73.6Β΅s  80.9Β΅s  | At illum ut est sit soluta nulla numquam.
#2   112ms   111.9ms | Sunt quaerat ea dolores facere deleniti culpa numquam.
#3   327.1ms 215.1ms | Distinctio maxime consequatur est qui corporis sunt officia.
#4   605.3ms 278.2ms | Et quia odit molestias voluptas porro repellendus magnam.
#5   897.7ms 292.3ms | Corporis eos rem non hic esse optio quisquam.
#6   1.1s    211.7ms | Natus earum molestias iste architecto porro et blanditiis.
#7   1.3s    238.2ms | Eum repellendus nostrum qui eius suscipit fugit quia.
#8   1.4s    50.6ms  | Et nesciunt quod fuga ut vel pariatur libero.
#9   1.6s    209.6ms | Rerum omnis soluta facilis voluptatem possimus et voluptas.
#10  1.9s    274.7ms | Possimus harum voluptatibus aperiam voluptatibus qui autem quam.
foo@bar:~$ generate-fake-data | prefix -format="{{.LineNumber3}} "
1   At illum ut est sit soluta nulla numquam.
2   Nobis sunt quaerat ea dolores facere deleniti culpa.
3   Numquam ut distinctio maxime consequatur est qui corporis.
4   Sunt officia odit et quia odit molestias voluptas.
5   Porro repellendus magnam ipsa corporis eos rem non.
6   Hic esse optio quisquam hic natus earum molestias.
7   Iste architecto porro et blanditiis iste eum repellendus.
8   Nostrum qui eius suscipit fugit quia quo et.
9   Nesciunt quod fuga ut vel pariatur libero sequi.
10  Rerum omnis soluta facilis voluptatem possimus et voluptas.
foo@bar:~$ generate-fake-data | prefix -format=">>> "
>>> At illum ut est sit soluta nulla numquam.
>>> Nobis sunt quaerat ea dolores facere deleniti culpa.
>>> Numquam ut distinctio maxime consequatur est qui corporis.
>>> Sunt officia odit et quia odit molestias voluptas.
>>> Porro repellendus magnam ipsa corporis eos rem non.
>>> Hic esse optio quisquam hic natus earum molestias.
>>> Iste architecto porro et blanditiis iste eum repellendus.
>>> Nostrum qui eius suscipit fugit quia quo et.
>>> Nesciunt quod fuga ut vel pariatur libero sequi.
>>> Rerum omnis soluta facilis voluptatem possimus et voluptas.
foo@bar:~$ generate-fake-data | prefix -format="{{SLOW_LINES}} up={{.ShortUptime}} | "
     876.7Β΅s  up=892.6Β΅s | Rerum natus quo quo explicabo tempore et delectus.
SLOW 1s       up=1.1s    | Dolor blanditiis voluptas dolorum sint laudantium eveniet amet.
SLOW 1.3s     up=2.4s    | Qui asperiores molestiae est quia est eum omnis.
SLOW 1.3s     up=3.6s    | Illum explicabo aut illum iste pariatur aut laudantium.
     982.2ms  up=4.6s    | Quibusdam asperiores consequatur est dolores quas dolor ipsam.
     185.5ms  up=4.8s    | Possimus qui non rem qui cum sit temporibus.
     167.5ms  up=5s      | Ea debitis sit deleniti cum ut adipisci in.
     520.3ms  up=5.5s    | Eveniet molestias voluptatem voluptatem deserunt nisi tempora iusto.
     215ms    up=5.7s    | Fugiat minus quam eos voluptatem labore sit velit.
SLOW 1s       up=6.7s    | Enim aut autem tenetur fugit minima quo atque.
foo@bar:~$ generate-fake-data | prefix -format="{{SHORT_DATE}} "
20/19/09 00:02:43 At illum ut est sit soluta nulla numquam.
20/19/09 00:02:44 Sunt quaerat ea dolores facere deleniti culpa numquam.
20/19/09 00:02:45 Distinctio maxime consequatur est qui corporis sunt officia.
20/19/09 00:02:46 Et quia odit molestias voluptas porro repellendus magnam.
20/19/09 00:02:48 Corporis eos rem non hic esse optio quisquam.
20/19/09 00:02:49 Natus earum molestias iste architecto porro et blanditiis.
20/19/09 00:02:50 Eum repellendus nostrum qui eius suscipit fugit quia.
20/19/09 00:02:50 Et nesciunt quod fuga ut vel pariatur libero.
20/19/09 00:02:51 Rerum omnis soluta facilis voluptatem possimus et voluptas.
20/19/09 00:02:53 Possimus harum voluptatibus aperiam voluptatibus qui autem quam.

Install

Using go
$ go get -u moul.io/prefix
Releases

See https://github.com/moul/prefix/releases

Contribute

I really welcome contributions. Your input is the most precious material. I'm well aware of that and I thank you in advance. Everyone is encouraged to look at what they can do on their own scale; no effort is too small.

Everything on contribution is sum up here: CONTRIBUTING.md

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):


Manfred Touron

🚧 πŸ“– ⚠️ πŸ’»

moul-bot

🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

Stargazers over time

Stargazers over time

License

Β© 2020-2021 Manfred Touron

Licensed under the Apache License, Version 2.0 (LICENSE-APACHE) or the MIT license (LICENSE-MIT), at your option. See the COPYRIGHT file for more details.

SPDX-License-Identifier: (Apache-2.0 OR MIT)

Documentation ΒΆ

Overview ΒΆ

message from the author:

+--------------------------------------------------------------+
| * * * β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘  Hello  β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘|
+--------------------------------------------------------------+
|                                                              |
|     ++              ______________________________________   |
|     ++++           /                                      \  |
|      ++++          |                                      |  |
|    ++++++++++      |   Feel free to contribute to this    |  |
|   +++       |      |       project or contact me on       |  |
|   ++         |     |    manfred.life if you like this     |  |
|   +  -==   ==|     |               project!               |  |
|  (   <*>   <*>     |                                      |  |
|   |          |    /|                  :)                  |  |
|   |         _)   / |                                      |  |
|   |      +++    /  \______________________________________/  |
|    \      =+   /                                             |
|     \      +                                                 |
|     |\++++++                                                 |
|     |  ++++      ||//                                        |
|  ___|   |___    _||/__                                     __|
| /    ---    \   \|  |||                   __ _  ___  __ __/ /|
|/  |       |  \    \ /                    /  ' \/ _ \/ // / / |
||  |       |  |    | |                   /_/_/_/\___/\_,_/_/  |
+--------------------------------------------------------------+

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var AvailablePatterns = map[string]string{
	`{{.LineNumber}}`:                `display line number`,
	`{{.LineNumber3}}`:               `alias for {{printf "%-3d" .LineNumber}}`,
	`{{.LineNumber4}}`:               `alias for {{printf "%-4d" .LineNumber}}`,
	`{{.LineNumber5}}`:               `alias for {{printf "%-5d" .LineNumber}}`,
	`{{.Format}}`:                    `the value you set with -format`,
	`{{.Uptime}}`:                    `time since the the prefixer was initialized`,
	`{{.Duration}}`:                  `time since previous line was started`,
	`{{.Uptime | short_duration}}`:   `{{.Uptime}} displayed in a pretty & short format (len<=7)`,
	`{{.Duration | short_duration}}`: `{{.Duration}} displayed in a pretty & short format (len<=7)`,
	`{{now}}`:                        `current date (format: 2006-01-02 15:04:05.999999999 -0700 MST)`,
	`{{now | unixEpoch}}`:            `current timestamp`,
	`{{uuidv4}}`:                     `UUID of the v4 (randomly generated) type`,
	`{{env "USER"}}`:                 `replace with content of the $USER env var`,
	`{{.ShortDuration}}`:             `alias for {{.Duration | short_duration}}`,
	`{{.ShortUptime}}`:               `alias for {{.Uptime | short_duration}}`,
}

AvailablePatterns is the list of available patterns to be used by the user.

This variable is only used to generate usage.

View Source
var AvailablePresets = map[string]string{
	"{{DEFAULT}}":    `{{.LineNumber3}} up={{.ShortUptime}} d={{.ShortDuration}} |`,
	"{{SLOW_LINES}}": `{{if (gt .Duration 1000000000)}}SLOW{{else}}    {{end}} {{.Duration | short_duration}} `,
	"{{SHORT_DATE}}": `{{now | date "06/02/01 15:04:05"}}`,
}

AvailablePresets is the list of available presets.

Those presets are automatically replaced during the initialization of the prefixer.

Functions ΒΆ

This section is empty.

Types ΒΆ

type LinePrefixer ΒΆ

type LinePrefixer interface {
	PrefixLine(string) string
}

func New ΒΆ

func New(format string) LinePrefixer

New returns an initialized LinePrefixer.

Directories ΒΆ

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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