1 /*
2 * Copyright (C) 2005 Tommi Maekitalo
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29 #include <cxxtools/log.h>
30 #include <cxxtools/arg.h>
31 #include <iostream>
32
33 const char* category = "logsh";
log_define(category)34 log_define(category)
35
36 int main(int argc, char* argv[])
37 {
38 try
39 {
40 cxxtools::Arg<bool> fatal;
41 fatal.set(argc, argv, 'f');
42 fatal.set(argc, argv, "--fatal");
43
44 cxxtools::Arg<bool> error;
45 error.set(argc, argv, 'e');
46 error.set(argc, argv, "--error");
47
48 cxxtools::Arg<bool> warn;
49 warn.set(argc, argv, 'w');
50 warn.set(argc, argv, "--warn");
51
52 cxxtools::Arg<bool> info;
53 info.set(argc, argv, 'i');
54 info.set(argc, argv, "--info");
55
56 cxxtools::Arg<bool> debug;
57 debug.set(argc, argv, 'd');
58 debug.set(argc, argv, "--debug");
59
60 cxxtools::Arg<std::string> properties("log4j.properties");
61 properties.set(argc, argv, 'p');
62 properties.set(argc, argv, "--properties");
63
64 if (argc <= 2)
65 {
66 std::cerr << "usage: " << argv[0] << " [options] category message\n"
67 "\toptions: -f|--fatal\n"
68 "\t -e|--error\n"
69 "\t -w|--warn\n"
70 "\t -i|--info\n"
71 "\t -d|--debug\n"
72 "\t -p|--properties filename" << std::endl;
73 return -1;
74 }
75
76 log_init(properties.getValue());
77
78 category = argv[1];
79
80 for (int a = 2; a < argc; ++a)
81 {
82 if (fatal)
83 log_fatal(argv[a]);
84 else if (error)
85 log_error(argv[a]);
86 else if (warn)
87 log_warn(argv[a]);
88 else if (info)
89 log_info(argv[a]);
90 else if (debug)
91 log_debug(argv[a]);
92 }
93 }
94 catch (const std::exception& e)
95 {
96 std::cerr << e.what() << std::endl;
97 return -1;
98 }
99 }
100
101