source: mainline/uspace/app/logset/main.c@ 60b1076

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

Fix usage help on logset

  • 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 logset
30 * @{
31 */
32/** @file Change logger behavior.
33 */
34#include <stdio.h>
35#include <async.h>
36#include <errno.h>
37#include <str_error.h>
38#include <io/logctl.h>
39
40static log_level_t parse_log_level_or_die(const char *log_level)
41{
42 log_level_t result;
43 int rc = log_level_from_str(log_level, &result);
44 if (rc != EOK) {
45 fprintf(stderr, "Unrecognised log level '%s': %s.\n",
46 log_level, str_error(rc));
47 exit(2);
48 }
49 return result;
50}
51
52static void usage(const char *progname)
53{
54 fprintf(stderr, "Usage:\n");
55 fprintf(stderr, " %s <default-logging-level>\n", progname);
56 fprintf(stderr, " %s <log-name> <logging-level>\n", progname);
57}
58
59int main(int argc, char *argv[])
60{
61 if (argc == 2) {
62 log_level_t new_default_level = parse_log_level_or_die(argv[1]);
63 int rc = logctl_set_default_level(new_default_level);
64
65 if (rc != EOK) {
66 fprintf(stderr, "Failed to change default logging level: %s.\n",
67 str_error(rc));
68 return 2;
69 }
70 } else if (argc == 3) {
71 log_level_t new_level = parse_log_level_or_die(argv[2]);
72 const char *logname = argv[1];
73 int rc = logctl_set_log_level(logname, new_level);
74
75 if (rc != EOK) {
76 fprintf(stderr, "Failed to change logging level: %s.\n",
77 str_error(rc));
78 return 2;
79 }
80 } else {
81 usage(argv[0]);
82 return 1;
83 }
84
85 return 0;
86}
87
88/** @}
89 */
Note: See TracBrowser for help on using the repository browser.