From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0726643DA2; Mon, 1 Apr 2024 13:18:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 81390402C9; Mon, 1 Apr 2024 13:18:49 +0200 (CEST) Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by mails.dpdk.org (Postfix) with ESMTP id 07FCB4028B for ; Mon, 1 Apr 2024 13:18:48 +0200 (CEST) Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-6146858b425so10932747b3.3 for ; Mon, 01 Apr 2024 04:18:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711970327; x=1712575127; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ar26jJHl4yYXDeJ7Z/DPjoIw+E3UYnn2qiyaP3IcG28=; b=c4lyFvDnTbvWviQ4m1YQJLzNNt70bU1yl9Rc2Rp94hvR3uAU3JyUToGR+wa4KknUYX QdzQRORRTHDFs2hUHsGZTEkW6vLYkxkHiKrSV6i/d1hhGmbw/FPcyGW1NeVdx+j7QZaC OMC7QJRyoXl0l9oO4iELQ8/pPxpme+nmSMoYTstnjaMkMIIfOIvhQrSyhq+AqI0vFAK6 IzlR2XmPNjEFjRf18NzRrCNcDw86H5SCFgHSvgagiUUO6UQf45qiGZauSNX0puIcq+Wk XK1SgWY+hMhoPxGE3Xdxbryzoxh5/Ay4CP4KHf0OJh5KvqQs8Fph6UE658Rdas+r/ejs YEDA== X-Gm-Message-State: AOJu0YxQUhXOs7rMfdvTBavHsnNvrwKxHS5CMkTdkkNopwIsS3RzPG4u BmRO6drgkDhRN74RgDqO1h60xRhWGDiNxFM85Ma1G7/Oo2l+foUaQDiIIaZj91U= X-Google-Smtp-Source: AGHT+IFCSyzSwMHuz8LR0kUm7Gp8BMirJ8OfmJBsNmyxVv0VCR4L2ZnLJggbKQ7TUreM4zJ3LYYl7g== X-Received: by 2002:a81:92c7:0:b0:613:f1d5:e36b with SMTP id j190-20020a8192c7000000b00613f1d5e36bmr8860363ywg.5.1711970327125; Mon, 01 Apr 2024 04:18:47 -0700 (PDT) Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com. [209.85.128.171]) by smtp.gmail.com with ESMTPSA id y76-20020a81a14f000000b00609eb1fc92esm1509316ywg.132.2024.04.01.04.18.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Apr 2024 04:18:47 -0700 (PDT) Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-61453963883so27095467b3.1 for ; Mon, 01 Apr 2024 04:18:47 -0700 (PDT) X-Received: by 2002:a0d:db52:0:b0:610:ecfb:1f86 with SMTP id d79-20020a0ddb52000000b00610ecfb1f86mr9100690ywe.23.1711970326692; Mon, 01 Apr 2024 04:18:46 -0700 (PDT) MIME-Version: 1.0 References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-1-stephen@networkplumber.org> <20240330164433.50144-14-stephen@networkplumber.org> In-Reply-To: <20240330164433.50144-14-stephen@networkplumber.org> From: Luca Boccassi Date: Mon, 1 Apr 2024 11:18:35 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v20 13/14] log: add support for systemd journal To: Stephen Hemminger Cc: dev@dpdk.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Sat, 30 Mar 2024 at 16:46, Stephen Hemminger wrote: > > If DPDK application is being run as a systemd service, then > it can use the journal protocol which allows putting more information > in the log such as priority and other information. > > The use of journal protocol is automatically detected and > handled. Rather than having a dependency on libsystemd, > just use the protocol directly as defined in: > https://systemd.io/JOURNAL_NATIVE_PROTOCOL/ > > Signed-off-by: Stephen Hemminger > --- > doc/guides/prog_guide/log_lib.rst | 14 ++ > lib/eal/common/eal_common_options.c | 11 ++ > lib/eal/common/eal_options.h | 2 + > lib/log/log.c | 5 + > lib/log/log_internal.h | 3 + > lib/log/log_journal.c | 200 ++++++++++++++++++++++++++++ > lib/log/log_private.h | 2 + > lib/log/log_stubs.c | 11 +- > lib/log/meson.build | 10 +- > lib/log/version.map | 1 + > 10 files changed, 255 insertions(+), 4 deletions(-) > create mode 100644 lib/log/log_journal.c This is very nice work, I like it a lot! > +/* > + * send structured message using journal protocol > + * See: https://systemd.io/JOURNAL_NATIVE_PROTOCOL/ > + */ > +static int > +journal_send(const char *buf, size_t len) > +{ > + struct iovec iov[4]; > + unsigned int n = 0; > + int priority = rte_log_cur_msg_loglevel() - 1; > + char msg[] = "MESSAGE="; > + char newline = '\n'; > + char pbuf[16]; /* "PRIORITY=N\n" */ > + > + iov[n].iov_base = msg; > + iov[n++].iov_len = strlen(msg); > + > + iov[n].iov_base = (char *)(uintptr_t)buf; > + iov[n++].iov_len = len; > + > + /* if message doesn't end with newline, one will be applied. */ > + if (buf[len - 1] != '\n') { > + iov[n].iov_base = &newline; > + iov[n++].iov_len = 1; > + } > + > + /* priority value between 0 ("emerg") and 7 ("debug") */ > + iov[n].iov_base = pbuf; > + iov[n++].iov_len = snprintf(pbuf, sizeof(pbuf), > + "PRIORITY=%d\n", priority); > + > + return writev(log_journal_fd, iov, n); > +} Doesn't need to be implemented immediately, but the nicest thing about talking directly to the journal is the ability to send lots of arbitrary and useful metadata together with a message, so would be nice if the logging function took an optional string vector that is appended, or some other such mechanism. A very useful example is creating a UUID and then setting MESSAGE_ID=uuid when logging particularly important messages that are useful to filter by this type - for example, when an interface state changes to up/down. That way, one can do 'journalctl MESSAGE_ID=abc..' and get all messages about interface state changes. A project can also ship a catalog file that adds additional context to each ID, that is automatically parsed and displayed to users.