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