LCOV - code coverage report
Current view: top level - log - output_option.h (source / functions) Hit Total Coverage
Test: report.info Lines: 4 4 100.0 %
Date: 2012-05-15 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 7 57.1 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
       2                 :            : //
       3                 :            : // Permission to use, copy, modify, and/or distribute this software for any
       4                 :            : // purpose with or without fee is hereby granted, provided that the above
       5                 :            : // copyright notice and this permission notice appear in all copies.
       6                 :            : //
       7                 :            : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
       8                 :            : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
       9                 :            : // AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
      10                 :            : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
      11                 :            : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
      12                 :            : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      13                 :            : // PERFORMANCE OF THIS SOFTWARE.
      14                 :            : 
      15                 :            : #ifndef __OUTPUT_OPTION_H
      16                 :            : #define __OUTPUT_OPTION_H
      17                 :            : 
      18                 :            : #include <stdint.h>
      19                 :            : #include <stdlib.h>
      20                 :            : #include <string>
      21                 :            : 
      22                 :            : /// \brief Logger Output Option
      23                 :            : ///
      24                 :            : /// The logging configuration options are a list of logger specifications, each
      25                 :            : /// with one or more output options.  This class represents an output option;
      26                 :            : /// one or more of these are attached to a LoggerSpecification object which is
      27                 :            : /// then passed to the LoggerManager to configure the logger.
      28                 :            : ///
      29                 :            : /// Although there are three distinct output types (console, file, syslog) and
      30                 :            : /// the options for each do not really overlap.  Although it is tempting to
      31                 :            : /// define a base OutputOption class and derive a class for each type
      32                 :            : /// (ConsoleOutputOptions etc.), it would be messy to use in practice.  At
      33                 :            : /// some point the exact class would have to be known to get the class-specific
      34                 :            : /// options and the (pointer to) the base class cast to the appropriate type.
      35                 :            : /// Instead, this "struct" contains the union of all output options; it is up
      36                 :            : /// to the caller to cherry-pick the members it needs.
      37                 :            : ///
      38                 :            : /// One final note: this object holds data and does no computation.  For this
      39                 :            : /// reason, it is a "struct" and members are accessed directly instead of
      40                 :            : /// through methods.
      41                 :            : 
      42                 :            : namespace isc {
      43                 :            : namespace log {
      44                 :            : 
      45         [ +  - ]:        586 : struct OutputOption {
      46                 :            : 
      47                 :            :     /// Destinations.  Prefixed "DEST_" to avoid problems with the C stdio.h
      48                 :            :     /// FILE type.
      49                 :            :     typedef enum {
      50                 :            :         DEST_CONSOLE = 0,
      51                 :            :         DEST_FILE = 1,
      52                 :            :         DEST_SYSLOG = 2
      53                 :            :     } Destination;
      54                 :            : 
      55                 :            :     /// If console, stream on which messages are output
      56                 :            :     typedef enum {
      57                 :            :         STR_STDOUT = 1,
      58                 :            :         STR_STDERR = 2
      59                 :            :     } Stream;
      60                 :            : 
      61                 :            :     /// \brief Constructor
      62                 :         24 :     OutputOption() : destination(DEST_CONSOLE), stream(STR_STDERR),
      63                 :            :                      flush(true), facility("LOCAL0"), filename(""),
      64      [ +  -  + ]:        423 :                      maxsize(0), maxver(0)
                 [ +  - ]
      65                 :         24 :     {}
      66                 :            : 
      67                 :            :     /// Members. 
      68                 :            : 
      69                 :            :     Destination     destination;        ///< Where the output should go
      70                 :            :     Stream          stream;             ///< stdout/stderr if console output
      71                 :            :     bool            flush;              ///< true to flush after each message
      72                 :            :     std::string     facility;           ///< syslog facility
      73                 :            :     std::string     filename;           ///< Filename if file output
      74                 :            :     size_t          maxsize;            ///< 0 if no maximum size
      75                 :            :     unsigned int    maxver;             ///< Maximum versions (none if <= 0)
      76                 :            : };
      77                 :            : 
      78                 :            : OutputOption::Destination getDestination(const std::string& dest_str);
      79                 :            : OutputOption::Stream getStream(const std::string& stream_str);
      80                 :            : 
      81                 :            : 
      82                 :            : } // namespace log
      83                 :            : } // namespace isc
      84                 :            : 
      85                 :            : #endif // __OUTPUT_OPTION_H

Generated by: LCOV version 1.9