summaryrefslogtreecommitdiffstats
path: root/logread.c
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2013-10-09 13:48:00 +0200
committerJohn Crispin <blogic@openwrt.org>2013-10-09 17:05:17 +0200
commitd5ee716c3519c024afdd0dd16362c99665d8bc60 (patch)
tree4a87ec03119bcd24e4b13e95addb608067e3a8c2 /logread.c
parenteba428f6672068d819d6296db3f635e6ac5a8be7 (diff)
downloadunitd-d5ee716c3519c024afdd0dd16362c99665d8bc60.tar
unitd-d5ee716c3519c024afdd0dd16362c99665d8bc60.zip
add a prefix option for messages streamed using logread
Signed-off-by: Robin Kuck <robin@basicinside.de>
Diffstat (limited to 'logread.c')
-rw-r--r--logread.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/logread.c b/logread.c
index bd8c697..81d2204 100644
--- a/logread.c
+++ b/logread.c
@@ -56,7 +56,7 @@ static const struct blobmsg_policy log_policy[] = {
static struct ubus_subscriber log_event;
static struct uloop_timeout retry;
static struct uloop_fd sender;
-static const char *log_file, *log_ip, *log_port, *pid_file;
+static const char *log_file, *log_ip, *log_port, *log_prefix, *pid_file;
static int log_type = LOG_STDOUT;
static int log_size, log_udp;
@@ -104,7 +104,7 @@ static int log_notify(struct ubus_context *ctx, struct ubus_object *obj,
{
struct blob_attr *tb[__LOG_MAX];
struct stat s;
- char buf[256];
+ char buf[512];
uint32_t p;
char *str;
time_t t;
@@ -140,8 +140,15 @@ static int log_notify(struct ubus_context *ctx, struct ubus_object *obj,
str = blobmsg_format_json(msg, true);
if (log_type == LOG_NET) {
int err;
+ int len;
- snprintf(buf, sizeof(buf), "%s%s\n",
+ *buf = '\0';
+ if (log_prefix)
+ snprintf(buf, sizeof(buf), "%s: ", log_prefix);
+
+ len = strlen(buf);
+
+ snprintf(&buf[len], sizeof(buf) - len, "%s%s\n",
(blobmsg_get_u32(tb[LOG_SOURCE])) ? ("") : ("kernel: "),
method);
if (log_udp)
@@ -280,6 +287,7 @@ static int usage(const char *prog)
" -F <file> Log file\n"
" -S <bytes> Log size\n"
" -p <file> PID file\n"
+ " -P <prefix> Prefix custom text to streamed messages\n"
" -f Follow log messages\n"
" -u Use UDP as the protocol\n"
"\n", prog);
@@ -294,7 +302,7 @@ int main(int argc, char **argv)
int ch, ret, subscribe = 0, lines = 0;
static struct blob_buf b;
- while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:")) != -1) {
+ while ((ch = getopt(argc, argv, "ufcs:l:r:F:p:S:P:")) != -1) {
switch (ch) {
case 'u':
log_udp = 1;
@@ -312,6 +320,9 @@ int main(int argc, char **argv)
case 'p':
pid_file = optarg;
break;
+ case 'P':
+ log_prefix = optarg;
+ break;
case 'f':
subscribe = 1;
break;