1 /*
2  * Copyright (c) 2018 Nordic Semiconductor ASA
3  * Copyright (c) 2016 Intel Corporation
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include "kernel_shell.h"
9 
10 #include <zephyr/logging/log_ctrl.h>
11 
cmd_kernel_log_level_set(const struct shell * sh,size_t argc,char ** argv)12 static int cmd_kernel_log_level_set(const struct shell *sh, size_t argc, char **argv)
13 {
14 	ARG_UNUSED(argc);
15 
16 	int err = 0;
17 
18 	uint8_t severity = shell_strtoul(argv[2], 10, &err);
19 
20 	if (err) {
21 		shell_error(sh, "Unable to parse log severity (err %d)", err);
22 
23 		return err;
24 	}
25 
26 	if (severity > LOG_LEVEL_DBG) {
27 		shell_error(sh, "Invalid log level: %d", severity);
28 		shell_help(sh);
29 		return SHELL_CMD_HELP_PRINTED;
30 	}
31 
32 	int source_id = log_source_id_get(argv[1]);
33 
34 	/* log_filter_set() takes an int16_t for the source ID */
35 	if (source_id < 0) {
36 		shell_error(sh, "Unable to find log source: %s", argv[1]);
37 	}
38 
39 	log_filter_set(NULL, 0, (int16_t)source_id, severity);
40 
41 	return 0;
42 }
43 
44 KERNEL_CMD_ARG_ADD(log_level, NULL, "<module name> <severity (0-4)>", cmd_kernel_log_level_set, 3,
45 		   0);
46