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 : #pragma once
26 :
27 : /** \file
28 : * \brief Environments from where a SNAP_LOG_... is used.
29 : *
30 : * Whenever you generate a log, the environment from that point in time
31 : * is registered in your message. This is very important since a log
32 : * can be handled by a different thread or even a different computer
33 : * and the appenders have to have the ability to show the PID, GID,
34 : * user name, group name, etc. from the original process and not
35 : * from the process that actually runs the appenders.
36 : */
37 :
38 : // self
39 : //
40 :
41 :
42 : // C++ lib
43 : //
44 : #include <memory>
45 : #include <string>
46 :
47 :
48 : // C lib
49 : //
50 : #include <unistd.h>
51 :
52 :
53 :
54 : namespace snaplogger
55 : {
56 :
57 :
58 1 : class environment
59 : {
60 : public:
61 : typedef std::shared_ptr<environment> pointer_t;
62 :
63 : environment(pid_t tid);
64 :
65 : uid_t get_uid() const;
66 : pid_t get_pid() const;
67 : gid_t get_gid() const;
68 : pid_t get_tid() const;
69 : std::string get_username() const;
70 : std::string get_groupname() const;
71 : std::string get_hostname() const;
72 : std::string get_domainname() const;
73 : std::string get_progname() const;
74 : std::string get_threadname() const;
75 :
76 : private:
77 : uid_t f_uid = -1;
78 : pid_t f_pid = -1;
79 : gid_t f_gid = -1;
80 : pid_t f_tid = -1;
81 : std::string f_username = std::string();
82 : std::string f_groupname = std::string();
83 : std::string f_hostname = std::string();
84 : std::string f_domainname = std::string();
85 : std::string f_progname = std::string();
86 : std::string f_threadname = std::string();
87 : };
88 :
89 :
90 : environment::pointer_t create_environment();
91 :
92 :
93 : } // snaplogger namespace
94 : // vim: ts=4 sw=4 et
|