Line data Source code
1 : /*
2 : * Copyright (c) 2013-2021 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 Appenders are used to append data to somewhere.
24 : *
25 : * This file declares the base appender class.
26 : */
27 :
28 :
29 : // self
30 : //
31 : #include "snaplogger/nested_diagnostic.h"
32 :
33 : #include "snaplogger/guard.h"
34 : #include "snaplogger/message.h"
35 : #include "snaplogger/private_logger.h"
36 :
37 :
38 : // last include
39 : //
40 : #include <snapdev/poison.h>
41 :
42 :
43 :
44 : namespace snaplogger
45 : {
46 :
47 :
48 :
49 3 : nested_diagnostic::nested_diagnostic(std::string const & diagnostic, bool emit_enter_exit_events)
50 3 : : f_emit_enter_exit_events(emit_enter_exit_events)
51 : {
52 3 : get_private_logger()->push_nested_diagnostic(diagnostic);
53 :
54 3 : if(f_emit_enter_exit_events)
55 : {
56 0 : SNAP_LOG_UNIMPORTANT
57 0 : << section(g_normal_component)
58 0 : << section(g_self_component)
59 : << "entering nested diagnostic"
60 : << SNAP_LOG_SEND;
61 : }
62 3 : }
63 :
64 :
65 6 : nested_diagnostic::~nested_diagnostic()
66 : {
67 3 : if(f_emit_enter_exit_events)
68 : {
69 0 : SNAP_LOG_UNIMPORTANT
70 0 : << section(g_normal_component)
71 0 : << section(g_self_component)
72 : << "exiting nested diagnostic"
73 : << SNAP_LOG_SEND;
74 : }
75 :
76 3 : get_private_logger()->pop_nested_diagnostic();
77 3 : }
78 :
79 :
80 0 : string_vector_t get_nested_diagnostics()
81 : {
82 0 : return get_private_logger()->get_nested_diagnostics();
83 : }
84 :
85 :
86 8 : string_vector_t get_nested_diagnostics(message const & msg)
87 : {
88 8 : return get_private_logger(msg)->get_nested_diagnostics();
89 : }
90 :
91 :
92 :
93 : } // snaplogger namespace
94 : // vim: ts=4 sw=4 et
|