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 Appender used to bufferize all the log data.
28 : *
29 : * This appender is a memory buffer. It is primarily used by the tests
30 : * to be able to verify all the other features avalaible in the library,
31 : * such as the line formatter.
32 : *
33 : * It could be useful to you in case you have to create a network connection
34 : * and do so in parallel. While the connection is being created, you may
35 : * want to bufferize the logs using this appender.
36 : *
37 : * Keep in mind that a buffer uses RAM which you may need for other things.
38 : */
39 :
40 : // self
41 : //
42 : #include "snaplogger/buffer_appender.h"
43 :
44 : #include "snaplogger/guard.h"
45 :
46 :
47 : // snapdev lib
48 : //
49 : #include <snapdev/lockfile.h>
50 :
51 :
52 : // C++ lib
53 : //
54 : #include <iostream>
55 :
56 :
57 : // C lib
58 : //
59 : #include <fcntl.h>
60 : #include <sys/stat.h>
61 : #include <sys/types.h>
62 :
63 :
64 : // last include
65 : //
66 : #include <snapdev/poison.h>
67 :
68 :
69 :
70 : namespace snaplogger
71 : {
72 :
73 :
74 : namespace
75 : {
76 :
77 :
78 :
79 8 : APPENDER_FACTORY(buffer);
80 :
81 :
82 :
83 : }
84 : // no name namespace
85 :
86 :
87 :
88 3 : buffer_appender::buffer_appender(std::string const name)
89 3 : : appender(name, "buffer")
90 : {
91 3 : }
92 :
93 :
94 32644 : void buffer_appender::process_message(message const & msg, std::string const & formatted_message)
95 : {
96 32644 : snap::NOTUSED(msg);
97 :
98 65288 : guard g;
99 :
100 32644 : *this << formatted_message;
101 32644 : }
102 :
103 :
104 :
105 :
106 :
107 6 : } // snaplogger namespace
108 : // vim: ts=4 sw=4 et
|