source: mainline/uspace/lib/c/generic/io/logctl.c@ b52dd1de

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b52dd1de was b52dd1de, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

Initial logging level can be set through sysinfo

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * Copyright (c) 2012 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32
33#include <assert.h>
34#include <unistd.h>
35#include <errno.h>
36#include <io/logctl.h>
37#include <ipc/logger.h>
38#include <sysinfo.h>
39#include <ns.h>
40
41#define SYSINFO_DEFAULT_LOG_LEVEL "logger.level"
42
43/** IPC session with the logger service. */
44static async_sess_t *logger_session = NULL;
45
46static int connect_to_logger()
47{
48 if (logger_session != NULL)
49 return EOK;
50
51 logger_session = service_connect_blocking(EXCHANGE_SERIALIZE,
52 SERVICE_LOGGER, LOGGER_INTERFACE_CONTROL, 0);
53 if (logger_session == NULL)
54 return ENOMEM;
55
56 return EOK;
57}
58
59
60int logctl_set_default_level(log_level_t new_level)
61{
62 int rc = connect_to_logger();
63 if (rc != EOK)
64 return rc;
65
66 async_exch_t *exchange = async_exchange_begin(logger_session);
67 if (exchange == NULL)
68 return ENOMEM;
69
70 rc = (int) async_req_1_0(exchange,
71 LOGGER_CTL_SET_DEFAULT_LEVEL, new_level);
72
73 async_exchange_end(exchange);
74
75 return rc;
76}
77
78int logctl_get_boot_level(log_level_t *level)
79{
80 sysarg_t boot_level_arg;
81 int rc = sysinfo_get_value(SYSINFO_DEFAULT_LOG_LEVEL, &boot_level_arg);
82 if (rc != EOK)
83 return rc;
84
85 log_level_t boot_level = (log_level_t) boot_level_arg;
86 if (boot_level >= LVL_LIMIT)
87 return EINVAL;
88
89 if (level != NULL)
90 *level = (log_level_t) boot_level;
91
92 return EOK;
93}
94
95/** @}
96 */
Note: See TracBrowser for help on using the repository browser.