LCOV - code coverage report
Current view: top level - snaplogger - severity.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 1 0.0 %
Date: 2019-08-13 00:35:33 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          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             : 
      28             : /** \file
      29             :  * \brief Severity levels for your log messages.
      30             :  *
      31             :  * The severity implementation loads the severity configuration file
      32             :  * and generates a set of severity levels that one can attach to
      33             :  * log messages.
      34             :  */
      35             : 
      36             : // self
      37             : //
      38             : #include    "snaplogger/utils.h"
      39             : 
      40             : 
      41             : // C++ lib
      42             : //
      43             : #include    <memory>
      44             : 
      45             : 
      46             : // C lib
      47             : //
      48             : #include    <sys/time.h>
      49             : 
      50             : 
      51             : 
      52             : namespace snaplogger
      53             : {
      54             : 
      55             : 
      56             : class message;
      57             : 
      58             : 
      59             : enum class severity_t
      60             : {
      61             :     SEVERITY_ALL                = 0,
      62             :     SEVERITY_TRACE              = 10,
      63             :     SEVERITY_DEBUG              = 20,
      64             :     SEVERITY_NOTICE             = 30,
      65             :     SEVERITY_UNIMPORTANT        = 40,
      66             :     SEVERITY_INFORMATION        = 50,
      67             :     SEVERITY_IMPORTANT          = 60,
      68             :     SEVERITY_MINOR              = 70,
      69             :     SEVERITY_DEPRECATED         = 80,
      70             :     SEVERITY_WARNING            = 100,
      71             :     SEVERITY_MAJOR              = 150,
      72             :     SEVERITY_RECOVERABLE_ERROR  = 190,
      73             :     SEVERITY_ERROR              = 200,
      74             :     SEVERITY_CRITICAL           = 210,
      75             :     SEVERITY_ALERT              = 220,
      76             :     SEVERITY_EMERGENCY          = 230,
      77             :     SEVERITY_FATAL              = 250,
      78             :     SEVERITY_OFF                = 255,
      79             : 
      80             :     SEVERITY_DEFAULT = SEVERITY_INFORMATION,
      81             :     SEVERITY_MIN = SEVERITY_ALL,
      82             :     SEVERITY_MAX = SEVERITY_OFF
      83             : };
      84             : 
      85             : 
      86             : 
      87             : 
      88           0 : class severity
      89             : {
      90             : public:
      91             :     typedef std::shared_ptr<severity>           pointer_t;
      92             : 
      93             :                         severity(severity_t sev, std::string const & name, bool system = false);
      94             : 
      95             :     severity_t          get_severity() const;
      96             :     bool                is_system() const;
      97             : 
      98             :     std::string         get_name() const;
      99             :     string_vector_t     get_all_names() const;
     100             : 
     101             :     void                add_alias(std::string const & name);
     102             :     string_vector_t     get_aliases() const;
     103             : 
     104             :     void                set_description(std::string const & description);
     105             :     std::string         get_description() const;
     106             : 
     107             :     void                set_styles(std::string const & color);
     108             :     std::string         get_styles() const;
     109             : 
     110             : private:
     111             :     severity_t const    f_severity;
     112             :     string_vector_t     f_names = string_vector_t();
     113             :     bool const          f_system;
     114             :     std::string         f_description = std::string();
     115             :     std::string         f_styles = std::string();
     116             : };
     117             : 
     118             : 
     119             : void                    add_severity(severity::pointer_t sev);
     120             : severity::pointer_t     get_severity(std::string const & name);
     121             : severity::pointer_t     get_severity(message const & msg, std::string const & name);
     122             : severity::pointer_t     get_severity(severity_t sev);
     123             : severity::pointer_t     get_severity(message const & msg, severity_t sev);
     124             : 
     125             : template<typename CharT, typename Traits>
     126             : inline std::basic_ostream<CharT, Traits> &
     127             : operator << (std::basic_ostream<CharT, Traits> & os, severity_t sev)
     128             : {
     129             :     severity::pointer_t s(get_severity(sev));
     130             :     if(s == nullptr)
     131             :     {
     132             :         os << "(unknown severity: "
     133             :            << static_cast<int>(sev)
     134             :            << ")";
     135             :     }
     136             :     else
     137             :     {
     138             :         os << s->get_name();
     139             :     }
     140             :     return os;
     141             : }
     142             : 
     143             : 
     144             : 
     145             : } // snaplogger namespace
     146             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.12