first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / loggers / combo_logger.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : combo_logger
4 *  Author : Chris Koeritz
5 *                                                                             *
6 *******************************************************************************
7 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
8 * redistribute it and/or modify it under the terms of the GNU General Public  *
9 * License as published by the Free Software Foundation; either version 2 of   *
10 * the License or (at your option) any later version.  This is online at:      *
11 *     http://www.fsf.org/copyleft/gpl.html                                    *
12 * Please send any updates to: fred@gruntose.com                               *
13 \*****************************************************************************/
14
15 #include "combo_logger.h"
16
17 #include <filesystem/directory.h>
18 #include <filesystem/filename.h>
19 #include <mathematics/chaos.h>
20 #include <structures/static_memory_gremlin.h>
21 #include <textual/parser_bits.h>
22
23 #ifdef __WIN32__
24   #include <io.h>
25 #endif
26 #include <stdio.h>
27 #ifdef __UNIX__
28   #include <unistd.h>
29 #endif
30
31 using namespace basis;
32 using namespace filesystem;
33 using namespace structures;
34 using namespace textual;
35
36 namespace loggers {
37
38 //const int REDUCE_FACTOR = 5;
39   // we whack this portion of the file every time we truncate.  if it's set
40   // to 14, for example, then a 14th of the file is whacked every time whacking
41   // is needed.
42
43 //const int MAXIMUM_BUFFER_SIZE = 140000;
44   // the maximum allowed chunk that can be copied from the old logfile
45   // to the current one.
46
47 //int static_chaos() { return chaos().inclusive(0, 1280004); }
48
49 combo_logger::combo_logger(const astring &filename, int limit, stream_choices target)
50 : file_logger(filename, limit),
51   console_logger(target)
52 {
53 }
54
55 void combo_logger::add_filter(int new_filter)
56 {
57   file_logger::add_filter(new_filter);
58   console_logger::add_filter(new_filter);
59 }
60
61 void combo_logger::remove_filter(int old_filter)
62 {
63   file_logger::remove_filter(old_filter);
64   console_logger::remove_filter(old_filter);
65 }
66
67 void combo_logger::clear_filters()
68 {
69   file_logger::clear_filters();
70   console_logger::clear_filters();
71 }
72
73 void combo_logger::eol(textual::parser_bits::line_ending to_set)
74 {
75   file_logger::eol(to_set);
76   console_logger::eol(to_set);
77 }
78
79 outcome combo_logger::log(const base_string &info, int filter)
80 {
81   console_logger::log(info, filter);
82   return file_logger::log(info, filter);
83 }
84
85 } //namespace.
86