summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-07-26 16:50:35 +0200
committerLennart Poettering <lennart@poettering.net>2012-07-26 16:56:21 +0200
commit498261871dfa2a930ec84b13a176e3bdc43aa212 (patch)
tree842bc005ca763ddc075ded82b0b74ec80f35d05e /src/journal
parent46b0d922256b62bc8291951d9868c243ced80c9a (diff)
journalctl: hightlight log lines by priority
warn/notice = bright white < error = red
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/journalctl.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index c924afbccc..abcfabe75d 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -198,6 +198,21 @@ static int parse_argv(int argc, char *argv[]) {
return 1;
}
+static bool on_tty(void) {
+ static int t = -1;
+
+ /* Note that this is invoked relatively early, before we start
+ * the pager. That means the value we return reflects whether
+ * we originally were started on a tty, not if we currently
+ * are. But this is intended, since we want colour and so on
+ * when run in our own pager. */
+
+ if (_unlikely_(t < 0))
+ t = isatty(STDOUT_FILENO) > 0;
+
+ return t;
+}
+
static int generate_new_id128(void) {
sd_id128_t id;
int r;
@@ -397,6 +412,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
+ on_tty();
have_pager = !arg_no_pager && !arg_follow && pager_open();
if (arg_output == OUTPUT_JSON) {
@@ -407,8 +423,10 @@ int main(int argc, char *argv[]) {
for (;;) {
for (;;) {
sd_id128_t boot_id;
- int flags = (arg_show_all*OUTPUT_SHOW_ALL |
- have_pager*OUTPUT_FULL_WIDTH);
+ int flags =
+ arg_show_all * OUTPUT_SHOW_ALL |
+ have_pager * OUTPUT_FULL_WIDTH |
+ on_tty() * OUTPUT_COLOR;
if (need_seek) {
r = sd_journal_next(j);