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