claw
1.9.0
Toggle main menu visibility
Loading...
Searching...
No Matches
application.cpp
Go to the documentation of this file.
1
/*
2
CLAW - a C++ Library Absolutely Wonderful
3
4
CLAW is a free library without any particular aim but being useful to
5
anyone.
6
7
Copyright (C) 2005-2011 Julien Jorge
8
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2.1 of the License, or (at your option) any later version.
13
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Lesser General Public License for more details.
18
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23
contact: julien.jorge@stuff-o-matic.com
24
*/
30
#include <
claw/application/application.hpp
>
31
32
#include <
claw/logger/log_stream_concise.hpp
>
33
#include <
claw/logger/log_stream_uniq.hpp
>
34
#include <
claw/logger/logger.hpp
>
35
36
#include <
claw/claw_gettext.hpp
>
37
42
#define CLAW_MK_STR_(e) #e
43
48
#define CLAW_MK_STR(e) CLAW_MK_STR_(e)
49
58
claw::application::application
(
int
& argc,
char
**& argv)
59
:
m_arguments
(argc, argv)
60
{
61
setlocale(LC_ALL,
""
);
62
#ifdef CLAW_TEXT_DOMAIN_PATH
63
bindtextdomain(
"libclaw"
,
CLAW_MK_STR
(CLAW_TEXT_DOMAIN_PATH));
64
#endif
65
bind_textdomain_codeset(
"libclaw"
,
"UTF-8"
);
66
textdomain(
"libclaw"
);
67
68
m_arguments
.add_long(
69
"--log-file"
,
claw_gettext
(
"The file to use to store log informations."
),
70
true
,
claw_gettext
(
"file"
));
71
m_arguments
.add_long(
72
"--log-level"
,
73
claw_gettext
(
"Level of log informations:\n"
74
"\t\terror: error messages,\n"
75
"\t\twarning: warning and error messages,\n"
76
"\t\tverbose: all messages."
),
77
true
,
claw_gettext
(
"string"
));
78
m_arguments
.add_long(
79
"--log-uniq"
,
80
claw_gettext
(
81
"Use a logger that does not output successively the same message."
),
82
true
);
83
m_arguments
.add_long(
84
"--log-concise"
,
85
claw_gettext
(
86
"Use a logger that does not output messages that have been recently"
87
" output."
),
88
true
,
claw_gettext
(
"integer"
));
89
90
m_arguments
.parse(argc, argv);
91
92
log_stream
* log;
93
94
if
(
m_arguments
.has_value(
"--log-file"
))
95
log =
new
file_logger
(
m_arguments
.get_string(
"--log-file"
));
96
else
97
log =
new
console_logger
;
98
99
if
(
m_arguments
.get_bool(
"--log-uniq"
))
100
log =
new
log_stream_uniq
(log);
101
else
if
(
m_arguments
.has_value(
"--log-concise"
)
102
&&
m_arguments
.only_integer_values(
"--log-concise"
)
103
&&
m_arguments
.get_integer(
"--log-concise"
) > 0)
104
log =
new
log_stream_concise
(log,
105
m_arguments
.get_integer(
"--log-concise"
));
106
else
if
(
m_arguments
.get_bool(
"--log-concise"
))
107
log =
new
log_stream_concise
(log);
108
109
logger
.set(log);
110
111
if
(
m_arguments
.has_value(
"--log-level"
))
112
{
113
std::string level =
m_arguments
.get_string(
"--log-level"
);
114
115
if
((level ==
"error"
) || (level ==
claw_gettext
(
"error"
)))
116
logger
.set_level(
log_error
);
117
else
if
((level ==
"warning"
) || (level ==
claw_gettext
(
"warning"
)))
118
logger
.set_level(
log_warning
);
119
else
if
((level ==
"verbose"
) || (level ==
claw_gettext
(
"verbose"
)))
120
logger
.set_level(
log_verbose
);
121
else
122
logger
.set_level(
m_arguments
.get_integer(
"--log-level"
));
123
}
124
}
125
129
claw::application::~application
()
130
{
131
logger
.clear();
132
}
CLAW_MK_STR
#define CLAW_MK_STR(e)
Build a char[] string representing an expression.
Definition
application.cpp:48
application.hpp
A class to represent the application.
claw::application::application
application(int &argc, char **&argv)
Constructor.
Definition
application.cpp:58
claw::application::m_arguments
arguments_table m_arguments
The arguments passed by the system.
Definition
application.hpp:70
claw::application::~application
virtual ~application()
Destructor.
Definition
application.cpp:129
claw::console_logger
This class write log messages in std::clog.
Definition
log_stream.hpp:75
claw::file_logger
This class write log messages in a file.
Definition
log_stream.hpp:88
claw::log_stream_concise
A log stream that does not output a message that have been recently output.
Definition
log_stream_concise.hpp:65
claw::log_stream_uniq
A log stream that does not output successively the same message.
Definition
log_stream_uniq.hpp:62
claw::log_stream
Base class for streams accepting log output.
Definition
log_stream.hpp:61
claw_gettext.hpp
Macros to call gettext on the libclaw textdomain.
claw_gettext
#define claw_gettext(s)
Call gettext on the default text domain used by Claw.
Definition
claw_gettext.hpp:39
log_stream_concise.hpp
A log stream that does not output a message that have been recently output.
log_stream_uniq.hpp
A log stream that does not output successively the same message.
logger.hpp
Some basic classes for logging.
claw::log_error
CLAW_LOGGER_EXPORT log_level log_error
Use this level if something goes really bad and your application may crash.
claw::log_warning
CLAW_LOGGER_EXPORT log_level log_warning
Use this level if a small problem occurs and you can deal with it without crashing the application.
claw::logger
CLAW_LOGGER_EXPORT log_system logger
The default log system provided by claw.
Definition
logger.cpp:37
claw::log_verbose
CLAW_LOGGER_EXPORT log_level log_verbose
Use this level if you want to inform the user about a situation that is not problematic.
lib
application
src
claw
application
application.cpp
Generated by
1.17.0