¿Cómo puedo resaltar las líneas de advertencia y error en la salida make?


A veces, la salida de make llena la pantalla. Es un poco difícil identificar todas las líneas de advertencia y mensaje de error. Sé que la salida de color de la cáscara puede ayudar ¿Puede alguien ayudarme?

Author: poolie, 2011-06-22

6 answers

Echa un vistazo a colormake, encontrado aquí

$ apt-cache search colormake
colormake - simple wrapper around make to colorize output

Usando el poder de Google, también encontré esta función bash.

make()
{
  pathpat="(/[^/]*)+:[0-9]+"
  ccred=$(echo -e "\033[0;31m")
  ccyellow=$(echo -e "\033[0;33m")
  ccend=$(echo -e "\033[0m")
  /usr/bin/make "$@" 2>&1 | sed -E -e "/[Ee]rror[: ]/ s%$pathpat%$ccred&$ccend%g" -e "/[Ww]arning[: ]/ s%$pathpat%$ccyellow&$ccend%g"
  return ${PIPESTATUS[0]}
}
 35
Author: Fredrik Pihl,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-25 14:17:03

He llegado a estas preguntas buscando una solución para colorear la salida make y luego recordé hace un tiempo que he investigado un buen colorizador de registro genérico y encontré ccze. Funciona con cualquier cosa que le arroje desde los registros del servidor de Minecraft a Exim MTA.

make | ccze -A

NOTA : especificar-Una opción habilita 'raw-ansi' de lo contrario alguna salida se 'borra' al final de la ejecución en mi experiencia. introduzca la descripción de la imagen aquí

 16
Author: Daniel Sokolowski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-04 03:43:13

Si eres un usuario de emacs, puedes usar el comando M-x compile. Esto pone la salida make en un búfer resaltado, con errores que actúan como enlaces a la línea relevante en el código fuente.

 6
Author: Dan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-06-23 06:32:57

¿Qué tal lo siguiente?

salida coloreada de make

Es producido por una versión simplificada de este Makefile.

PROJECT = programname
SHELL   = /bin/bash
OBJS    = $(patsubst src/%.cc,obj/%.o,$(wildcard src/*.cc))

RESET          = \033[0m
make_std_color = \033[3$1m      # defined for 1 through 7
make_color     = \033[38;5;$1m  # defined for 1 through 255
WRN_COLOR = $(strip $(call make_std_color,3))
ERR_COLOR = $(strip $(call make_std_color,1))
STD_COLOR = $(strip $(call make_color,8))

COLOR_OUTPUT = 2>&1 |                                   \
    while IFS='' read -r line; do                       \
        if  [[ $$line == *:[\ ]error:* ]]; then         \
            echo -e "$(ERR_COLOR)$${line}$(RESET)";     \
        elif [[ $$line == *:[\ ]warning:* ]]; then      \
            echo -e "$(WRN_COLOR)$${line}$(RESET)";     \
        else                                            \
            echo -e "$(STD_COLOR)$${line}$(RESET)";     \
        fi;                                             \
    done; exit $${PIPESTATUS[0]};

.PHONY: $(PROJECT)

$(PROJECT): bin/$(PROJECT)

bin/$(PROJECT): $(OBJS)
    @mkdir -p bin
    @echo g++ -o $@ $(OBJS) -Iinclude
    @g++ -o $@ $(OBJS) -Iinclude $(COLOR_OUTPUT)

obj/%.o: src/%.cc
    @mkdir -p obj
    @echo g++ -o $@ -c $< -Wall -Wextra
    @g++ -o $@ -c $< -Wall -Wextra $(COLOR_OUTPUT)

Asume que todos los archivos fuente de C++ están en el directorio src (extention .cc) y los archivos de cabecera están en el directorio include.

 3
Author: gospes,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-23 13:52:39

Otra función bash, muy concisa

make()
{
  /usr/bin/make "$@" 2>&1 | sed -E -e "s/error/ $(echo -e "\\033[31m" ERROR "\\033[0m"/g)"   -e "s/warning/ $(echo -e "\\033[0;33m" WARNING "\\033[0m"/g)"
  return ${PIPESTATUS[0]}
}
 3
Author: Jain Rach,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-06 08:39:08

Solía usar multitail para archivos de registro puede resaltar (y filtrar) líneas basadas en varios criterios.

 1
Author: Zsolt Botykai,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-06 12:10:19