d47586bfce4452fa9fa33914a4f8cdc302b0ed41
[profile/ivi/murphy.git] / src / core / console-log.c
1
2 static void log_level(mrp_console_t *c, void *user_data,
3                       int argc, char **argv)
4 {
5     mrp_log_mask_t mask;
6     char           buf[256];
7
8     MRP_UNUSED(c);
9     MRP_UNUSED(user_data);
10
11     if (argc == 2)
12         mask = mrp_log_get_mask();
13     else {
14         mask = mrp_log_parse_levels(argv[2]);
15         mrp_log_set_mask(mask);
16     }
17
18     printf("current logging mask: %s\n",
19            mrp_log_dump_mask(mask, buf, sizeof(buf)));
20 }
21
22
23 static void log_target(mrp_console_t *c, void *user_data,
24                        int argc, char **argv)
25 {
26     const char *target;
27     const char *targets[32];
28     int         i, n;
29
30     MRP_UNUSED(c);
31     MRP_UNUSED(user_data);
32
33     if (argc == 2) {
34         target = mrp_log_get_target();
35         n      = mrp_log_get_targets(targets, MRP_ARRAY_SIZE(targets));
36
37         printf("available log targets:\n");
38         for (i = 0; i < n; i++)
39             printf("    %s%s\n", targets[i],
40                    !strcmp(targets[i], target) ? " (active)" : "");
41     }
42     else if (argc == 3) {
43         target = argv[2];
44
45         if (!mrp_log_set_target(target))
46             printf("failed to change logging target to %s", target);
47         else {
48             printf("changed log target to %s\n", target);
49             mrp_log_info("changed log target to %s", target);
50         }
51     }
52     else {
53         printf("%s/%s invoked with wrong number of arguments\n",
54                argv[0], argv[1]);
55     }
56 }
57
58
59
60
61 #define LOG_GROUP_DESCRIPTION                                               \
62     "Log commands provide means to configure the active logging settings\n" \
63     "of Murphy. Commands are provided for changing the logging level,\n"    \
64     "listing log targets, and settting the active target.\n"
65
66 #define LEVEL_SYNTAX      "[[info[,warning[,error]]]]"
67 #define LEVEL_SUMMARY     "change or show the active logging level"
68 #define LEVEL_DESCRIPTION \
69     "Changes the logging level to the given one. Without arguments it\n" \
70     "prints out the current logging level.\n"
71
72 #define TARGET_SYNTAX      "[stdout|stderr|syslog|<other targets>]"
73 #define TARGET_SUMMARY     "change or show the active logging target"
74 #define TARGET_DESCRIPTION \
75     "Changes the active logging target to the given one. Without arguments\n" \
76     "it lists the available targets and the currently active one."
77
78 MRP_CORE_CONSOLE_GROUP(log_group, "log", LOG_GROUP_DESCRIPTION, NULL, {
79         MRP_TOKENIZED_CMD("level" , log_level , FALSE,
80                           LEVEL_SYNTAX , LEVEL_SUMMARY , LEVEL_DESCRIPTION),
81         MRP_TOKENIZED_CMD("target", log_target, FALSE,
82                           TARGET_SYNTAX, TARGET_SUMMARY, TARGET_DESCRIPTION)
83 });