Why won't journalctl show logs when the program output is piped?

Cole

I'm trying to run my docker-compose containers via a systemd service, and have fail2ban read their logs. However, docker-compose adds a prefix like:

container_name_1 | Actual log message

So what I'm trying to do is something like docker-compose up --no-color 2>&1 | sed 's/^[^ ]* *| //' to strip that prefix so that fail2ban can match on the log lines correctly. But when I do that, I only see Started mydockercontainers.service in the journalctl logs. Removing the pipe to sed fixes everything.

How can I remove this prefix and keep the log messages in the journal?

user1686

Most programs including sed will use block buffering, not line buffering, when their output is something else than an interactive tty device. (For services, the stdout is a pipe and you would see a similar effect with sed | cat.)

This means output will be delayed while it accumulates in the buffer – it will only be written in chunks of 10-20 lines or so (however many fit in a 4kB buffer). Use the sed -u or --unbuffered option to disable the buffering.

In cases where the program doesn't have such an option, wrap it with stdbuf -i0 -o0.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Program output changes when piped

From Dev

Why don't some "for" commands work when the output is piped?

From Dev

LogCat won't show my logs

From Dev

How does a program output to a terminal when stdout is piped?

From Java

Why set logging level for each module won't show logs in my code?

From Dev

Why won't `text` show when customdialog is opened?

From Dev

Why won't results show in order when using count(*) DESC

From Dev

Why won't results show in order when using count(*) DESC

From Java

Why won't this program print?

From Dev

Why won't the program exit?

From Dev

Why does bash output data instead of executing, when a script is piped?

From Dev

Why isn't apt-cache policy output piped?

From Dev

c++ program won't output as expected

From Dev

Why journalctl don't save my logs of the boot before forced shutdown?

From Dev

DDMS Won't Show Debug Output

From Dev

DDMS Won't Show Debug Output

From Dev

Why won't my program work in python?

From Dev

Why won't my "Circle" program run?

From Dev

Why won't my program work in python?

From Dev

Why won't this simple Morte program typecheck?

From Dev

Why won't my background image show?

From Dev

Why won't all the records show?

From Dev

Why Won't the BG Colors Show Up?

From Dev

Why won't the output be 4 in this case?

From Dev

Why won't the JFrame display the output?

From Dev

Use journalctl to show logs of specific unit which has a parameter?

From Dev

why won't my program accept int[] parameter in method when called in main?

From Dev

Why sometimes when i run a program in terminal, it won't run in the terminal?

From Dev

Program doesn't show expected output

Related Related

HotTag

Archive