LCOV - code coverage report
Current view: top level - snaplogger - component.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 4 25.0 %
Date: 2021-08-20 16:41:45 Functions: 1 4 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2013-2021  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/snaplogger
       4             : // contact@m2osw.com
       5             : //
       6             : // This program is free software; you can redistribute it and/or modify
       7             : // it under the terms of the GNU General Public License as published by
       8             : // the Free Software Foundation; either version 2 of the License, or
       9             : // (at your option) any later version.
      10             : //
      11             : // This program is distributed in the hope that it will be useful,
      12             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             : // GNU General Public License for more details.
      15             : //
      16             : // You should have received a copy of the GNU General Public License along
      17             : // with this program; if not, write to the Free Software Foundation, Inc.,
      18             : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      19             : #pragma once
      20             : 
      21             : /** \file
      22             :  * \brief Define the component class used as a way to group messages.
      23             :  *
      24             :  * Whenever you send a log, you can assign one or more components to it.
      25             :  *
      26             :  * By default, when a log component's list is empty, it is viewed as if
      27             :  * the list was only composed of the "normal" component.
      28             :  *
      29             :  * Errors generated by the snaplogger library include the "normal" and
      30             :  * "self" components.
      31             :  *
      32             :  * The library also offers a "debug" and "secure" set of components.
      33             :  *
      34             :  * To use these components and your own, use the section() function like so:
      35             :  *
      36             :  * \code
      37             :  *     SNAP_LOG_SEND
      38             :  *         << snaplogger::section(g_normal_component)
      39             :  *         << snaplogger::section(g_self_component)
      40             :  *         << "Message..."
      41             :  *         << SNAP_LOG_SEND;
      42             :  * \endcode
      43             :  *
      44             :  * For the "secure" component, you can also use the special ending macro
      45             :  * like so:
      46             :  *
      47             :  * \code
      48             :  *     SNAP_LOG_SEND
      49             :  *         << snaplogger::section(g_debug_component)
      50             :  *         << "Message..."
      51             :  *         << SNAP_LOG_SEND_SECURELY;
      52             :  * \endcode
      53             :  *
      54             :  * You cannot include "normal" and "secure" to the same message (they are
      55             :  * mutually exclusive). Trying to do so will generate an exception.
      56             :  *
      57             :  * \warning
      58             :  * Do NOT create a component directly. The only real interface accessible
      59             :  * to create a component as far as you're concerned are the get_component()
      60             :  * functions. One includes a message which means we have a direct access
      61             :  * to the private logger object.
      62             :  */
      63             : 
      64             : 
      65             : // C++ lib
      66             : //
      67             : #include    <map>
      68             : #include    <memory>
      69             : #include    <set>
      70             : #include    <string>
      71             : 
      72             : 
      73             : 
      74             : namespace snaplogger
      75             : {
      76             : 
      77             : 
      78             : class message;
      79             : class private_logger;
      80             : 
      81             : 
      82          18 : class component
      83             : {
      84             : public:
      85             :     typedef std::shared_ptr<component>          pointer_t;
      86             :     typedef std::map<std::string, pointer_t>    map_t;
      87             :     typedef std::set<pointer_t>                 set_t;
      88             : 
      89             :     std::string const &         get_name() const;
      90             : 
      91             :     void                        add_mutually_exclusive_components(set_t components);
      92             :     bool                        is_mutually_exclusive(pointer_t other_component) const;
      93             :     bool                        is_mutually_exclusive(set_t const & other_component) const;
      94             : 
      95             : private:
      96             :     friend private_logger;
      97             : 
      98             :                                 component(std::string const & name);
      99             : 
     100             :     std::string const           f_name;
     101             :     set_t                       f_mutually_exclusive_components = {};
     102             : };
     103             : 
     104             : 
     105             : 
     106             : component::pointer_t            get_component(std::string const & name);
     107             : component::pointer_t            get_component(std::string const & name, component::set_t mutually_exclusive);
     108             : component::pointer_t            get_component(message const & msg, std::string const & name);
     109             : 
     110             : 
     111             : constexpr char const            COMPONENT_CPPTHREAD[] = "cppthread";
     112             : constexpr char const            COMPONENT_DEBUG[]     = "debug";
     113             : constexpr char const            COMPONENT_NORMAL[]    = "normal";
     114             : constexpr char const            COMPONENT_SECURE[]    = "secure";
     115             : constexpr char const            COMPONENT_SELF[]      = "self"; // for the snaplogger only
     116             : constexpr char const            COMPONENT_BANNER[]    = "banner";
     117             : 
     118             : extern component::pointer_t     g_cppthread_component;
     119             : extern component::pointer_t     g_debug_component;
     120             : extern component::pointer_t     g_normal_component;
     121             : extern component::pointer_t     g_secure_component;
     122             : extern component::pointer_t     g_self_component;
     123             : extern component::pointer_t     g_banner_component;
     124             : 
     125             : 
     126           0 : struct section_ptr
     127             : {
     128             :     component::pointer_t    f_component;
     129             : };
     130             : 
     131           0 : inline section_ptr section(component::pointer_t comp)
     132             : {
     133           0 :     return { comp };
     134             : }
     135             : 
     136             : 
     137             : 
     138             : 
     139             : 
     140             : } // snaplogger namespace
     141             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13