first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / loggers / combo_logger.h
1 #ifndef COMBO_LOGGER_CLASS
2 #define COMBO_LOGGER_CLASS
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : combo_logger
7 *  Author : Chris Koeritz
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
11 * redistribute it and/or modify it under the terms of the GNU General Public  *
12 * License as published by the Free Software Foundation; either version 2 of   *
13 * the License or (at your option) any later version.  This is online at:      *
14 *     http://www.fsf.org/copyleft/gpl.html                                    *
15 * Please send any updates to: fred@gruntose.com                               *
16 \*****************************************************************************/
17
18 #include "file_logger.h"
19
20 namespace loggers {
21
22 //! combines a file_logger with a console logger, behaving like the 'tee' command.
23 /*! this will output the diagnostic info to both a file and to the console.  this is useful
24 when one would like to see the output as its happening but also have a record for later.  */
25
26 class combo_logger : public virtual file_logger, public virtual console_logger
27 {
28 public:
29   combo_logger(const basis::astring &filename,
30       int limit = DEFAULT_LOG_FILE_SIZE,
31       stream_choices log_target = TO_STDOUT);
32
33   virtual ~combo_logger() {}
34
35   DEFINE_CLASS_NAME("combo_logger");
36
37   virtual basis::outcome log(const basis::base_string &info, int filter = basis::ALWAYS_PRINT);
38
39   // overrides that enforce properties for both loggers.
40   virtual void add_filter(int new_filter);
41   virtual void remove_filter(int old_filter);
42   virtual void clear_filters();
43   virtual void eol(textual::parser_bits::line_ending to_set);
44 };
45
46 //////////////
47
48 //! a macro that retasks the program-wide logger as a combo_logger.
49 #define SETUP_COMBO_LOGGER { \
50   basis::base_logger *old_log = program_wide_logger::set \
51       (new loggers::combo_logger \
52           (loggers::file_logger::log_file_for_app_name())); \
53   WHACK(old_log); \
54 }
55
56 } //namespace.
57
58 #endif
59