2

I am using the following simple function to provide some well readable output to the user. Now I am wondering if there is some kind of (gentoo-/bash-) built-in function to accomplish this task, as this feels like 're-inventing' the wheel. Thanks in advance.

function log
{
        red='\033[0;31m'
        green='\033[0;32m'
        yellow='\033[1;33m'
        term='\033[0m'

        if [ "$1" == "INFO" ]; then
                echo -e "${green}[i] $2 ${term}"
        elif [ "$1" == "WARN" ]; then
                echo -e "${yellow}[w] $2 ${term}"
        elif [ "$1" == "ERROR" ]; then
                echo -e "${red}[e] $2 ${term}"
        fi
}

3 Answers3

1

I'm not sure what are you trying to achieve, but if your function will somehow interact with portage then perhaps you could use its color definition. From man 5 color.map:

VARIABLES
       NORMAL = "normal"
              Defines color used for some words  occuring  in  other  contexts  than  those
              below.

       BAD = "red"
              Defines color used for some words occuring in bad context.

       BRACKET = "blue"
              Defines color used for brackets.

       GOOD = "green"
              Defines color used for some words occuring in good context.

       HILITE = "teal"
              Defines color used for highlighted words.

       INFORM = "darkgreen"
              Defines color used for informational words.

       [...]

       SECURITY_WARN = "red"
              Defines color used for security warnings.

       UNMERGE_WARN = "red"
              Defines color used for unmerge warnings.

       WARN = "yellow"
          Defines color used for warnings.
jimmij
  • 47,140
1

There are no built-in function to colourize logs, but there's

  • Vim with its messages highlighter that makes logs easier to read and also highlights lines with certain keywords ("error", "failed", etc.) in red.
    Try :setf messages.

  • ccze - A robust log colorizer — a replacement for colorize that apparently has lots of ways to customize it colourization features.

  • colortail, which "is basically tail but with support for colors."

  • and a bunch of other tools — see this question for some more

n.st
  • 8,128
0

Consider Enabling Portage ELogging.

Taken from the Gentoo Wiki: Portage Log.

Inside /etc/portage/make.conf:

  1. Set PORT_LOGDIR, i.e.
    PORT_LOGDIR="/var/log/portage"
  2. Set PORTAGE_ELOG_CLASSES, i.e.
    PORTAGE_ELOG_CLASSES="log warn error"
  3. Set PORTAGE_ELOG_SYSTEM, i.e.
    PORTAGE_ELOG_SYSTEM="save"

You can also set Option 3 differently depending on your needs.

For mailing logs to some recipient, you should enable the mail module instead, and set some additional variables, too. Please read /usr/share/portage/config/make.conf.example for details.

eyoung100
  • 6,252
  • 23
  • 53