Line data Source code
1 : /*
2 : * Copyright (c) 2013-2019 Made to Order Software Corp. All Rights Reserved
3 : *
4 : * https://snapwebsites.org/project/snaplogger
5 : * contact@m2osw.com
6 : *
7 : * This program is free software; you can redistribute it and/or modify
8 : * it under the terms of the GNU General Public License as published by
9 : * the Free Software Foundation; either version 2 of the License, or
10 : * (at your option) any later version.
11 : *
12 : * This program is distributed in the hope that it will be useful,
13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : * GNU General Public License for more details.
16 : *
17 : * You should have received a copy of the GNU General Public License along
18 : * with this program; if not, write to the Free Software Foundation, Inc.,
19 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 : */
21 :
22 : /** \file
23 : * \brief Implementation of the components.
24 : *
25 : * This file implements the component base classes.
26 : */
27 :
28 : // self
29 : //
30 : #include "snaplogger/component.h"
31 :
32 : #include "snaplogger/exception.h"
33 : #include "snaplogger/guard.h"
34 : #include "snaplogger/private_logger.h"
35 :
36 :
37 : // snapdev lib
38 : //
39 : #include <snapdev/not_used.h>
40 :
41 :
42 : // C++ lib
43 : //
44 : #include <map>
45 :
46 :
47 : // last include
48 : //
49 : #include <snapdev/poison.h>
50 :
51 :
52 :
53 : namespace snaplogger
54 : {
55 :
56 :
57 :
58 2 : component::pointer_t g_debug_component(get_component(COMPONENT_DEBUG));
59 2 : component::pointer_t g_normal_component(get_component(COMPONENT_NORMAL));
60 2 : component::pointer_t g_secure_component(get_component(COMPONENT_SECURE));
61 :
62 :
63 : /** \brief Create a new component.
64 : *
65 : * \warning
66 : * DO NOT CREATE A COMPONENT DIRECTLY.
67 : *
68 : * Please use the get_component() function whenever you want to create
69 : * a new component. If it already exists, then the existing one will
70 : * be returned.
71 : *
72 : * It is not possible to register the same component more than once.
73 : * The get_component() function makes sure that won't happen.
74 : *
75 : * \param[in] name The name of the new component.
76 : */
77 6 : component::component(std::string const & name)
78 6 : : f_name(name)
79 : {
80 6 : }
81 :
82 :
83 0 : std::string const & component::get_name() const
84 : {
85 0 : return f_name;
86 : }
87 :
88 :
89 24 : component::pointer_t get_component(std::string const & name)
90 : {
91 24 : return get_private_logger()->get_component(name);
92 : }
93 :
94 :
95 0 : component::pointer_t get_component(message const & msg, std::string const & name)
96 : {
97 0 : return get_private_logger(msg)->get_component(name);
98 : }
99 :
100 :
101 6 : } // snaplogger namespace
102 : // vim: ts=4 sw=4 et
|