Rabarar's Blog

A blogging framework for mild hackers.

Color My World! Or at Least My Logfiles

| Comments

Here’s a fun little git I came across from Antoine Grondin. It’s a cute little logfile color package to make your logfiles really pop!

Tired of those old boring foreground on background logs? Well, try this!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   package main

  import (
      "log"
      "os"
      "time"

      "github.com/aybabtme/rgbterm/rainbow"
  )

  func main() {
      joyfulOutput := rainbow.New(os.Stderr, 252, 255, 43)
      log.SetOutput(joyfulOutput)

      for i := 0; i < 500; i++ {
          log.Printf("This is surely going to drive you nuts!\n")
          time.Sleep(250 * time.Millisecond)
      }

  }

Okay, that’s sure to get you screamed at if you actually used it. But a more useful package used by the rainbow package is the rgbterm package. This package lets you color any text and display it on stdout.

Here’s an example using this package:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   package main

  import (
      "fmt"

      "github.com/aybabtme/rgbterm"
  )

  func main() {

      var r, g, b uint8
      // pick a color
      r, g, b = 255, 255, 255
      // choose a word
      word := "=)"
      // colorize it!
      coloredWord := rgbterm.String(word, r, g, b, r^r, g^g, b^b)

      fmt.Println("Oh!", coloredWord, "hello!")
  }

Enjoy!

Comments