1 /* Copyright (C) 2014 InfiniDB, Inc.
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License
5 as published by the Free Software Foundation; version 2 of
6 the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 MA 02110-1301, USA. */
17
18 // $Id: main.cpp 2336 2013-06-25 19:11:36Z rdempsey $
19
20 #include <unistd.h>
21 #include <cstdio>
22 #include <iostream>
23 using namespace std;
24
25 #include "messageobj.h"
26 #include "messagelog.h"
27 #include "loggingid.h"
28 using namespace logging;
29
30 namespace
31 {
usage()32 void usage()
33 {
34 cout << "usage: cplogger [-s subsys] [-cwi] [-h] msg_id [args...]" << endl;
35 }
36 }
37
main(int argc,char ** argv)38 int main(int argc, char** argv)
39 {
40 int c;
41 opterr = 0;
42 bool cflg = true;
43 bool wflg = false;
44 unsigned subsysID = 8; //oamcpp
45
46 while ((c = getopt(argc, argv, "s:cwih")) != EOF)
47 switch (c)
48 {
49 case 'c':
50 cflg = true;
51 wflg = false;
52 break;
53
54 case 'w':
55 cflg = false;
56 wflg = true;
57 break;
58
59 case 'i':
60 cflg = false;
61 wflg = false;
62 break;
63
64 case 's':
65 subsysID = strtoul(optarg, 0, 0);
66 break;
67
68 case 'h':
69 case '?':
70 default:
71 usage();
72 return (c == 'h' ? 0 : 1);
73 break;
74 }
75
76 if ((argc - optind) < 1)
77 {
78 usage();
79 return 1;
80 }
81
82 Message::MessageID mid = strtoul(argv[optind++], 0, 0);;
83 Message::Args args;
84
85 for (int i = optind; i < argc; i++)
86 args.add(argv[optind++]);
87
88 LoggingID logInfo(subsysID);
89 Message msg(mid);
90 msg.format(args);
91 MessageLog log(logInfo);
92
93 if (cflg)
94 log.logCriticalMessage(msg);
95 else if (wflg)
96 log.logWarningMessage(msg);
97 else
98 log.logInfoMessage(msg);
99
100 return 0;
101 }
102
103