feisty meow concerns codebase 2.140
file_logger.h
Go to the documentation of this file.
1#ifndef FILE_LOGGER_CLASS
2#define FILE_LOGGER_CLASS
3
4/*****************************************************************************\
5* *
6* Name : file_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
19
24#include "console_logger.h"
25#include "eol_aware.h"
26#include "filter_set.h"
27
28#include <basis/astring.h>
29#include <basis/contracts.h>
30#include <basis/functions.h>
31#include <basis/mutex.h>
33#include <textual/parser_bits.h>
34
35namespace loggers {
36
37class file_logger : public virtual standard_log_base
38{
39public:
42
46
49 virtual ~file_logger();
50
51 DEFINE_CLASS_NAME("file_logger");
52
53 enum limits {
55 DEFAULT_LOG_FILE_SIZE = 0x10F00D
56 };
57
58 bool good() const;
60
63 bool reopen();
65
67 basis::outcome log(const basis::base_string &info, int filter = basis::ALWAYS_PRINT);
69
73 basis::outcome log_bytes(const basis::byte_array &to_log, int filter = basis::ALWAYS_PRINT);
75
77 basis::outcome format_bytes(const basis::byte_array &to_log, int filter = basis::ALWAYS_PRINT);
79
80 basis::astring name() const;
82 void name(const basis::astring &new_name);
84
87 int limit() const { return int(_file_limit); }
89 void limit(int new_limit) { _file_limit = new_limit; }
91
92 void flush();
94
95 void truncate(size_t new_size);
97
100
104
105private:
106 basis::astring *_filename;
107 size_t _file_limit;
108 filesystem::byte_filer *_outfile;
109 basis::mutex *_flock;
110
111 int size_reduction() const;
113
115 bool open_file();
117
119 void close_file();
121
122 // unavailable.
123 file_logger(const file_logger &);
124 file_logger &operator =(const file_logger &);
125};
126
128
130#define SETUP_FILE_LOGGER { \
131 loggers::standard_log_base *old_log = loggers::program_wide_logger::set \
132 (new loggers::file_logger(loggers::file_logger::log_file_for_app_name())); \
133 WHACK(old_log); \
134}
135
136} //namespace.
137
138#endif
139
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
Defines the base class for all string processing objects in hoople.
Definition base_string.h:28
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
Outcomes describe the state of completion for an operation.
Definition outcome.h:31
Provides file managment services using the standard I/O support.
Definition byte_filer.h:32
bool reopen()
closes the current file and attempts to reopen it.
bool good() const
returns true if the logger appears correctly hooked up to a file.
@ DEFAULT_LOG_FILE_SIZE
this just defines the default for the log file size.
Definition file_logger.h:55
basis::astring name() const
observes the filename where logged information is written.
void flush()
causes any pending writes to be sent to the output file.
static basis::astring log_file_for_app_name()
returns a log file name for file_logger based on the program name.
void truncate(size_t new_size)
chops the file to ensure it doesn't go much over the file size limit.
DEFINE_CLASS_NAME("file_logger")
file_logger()
creates a logger without a log file and with the default size limit.
void limit(int new_limit)
modifies the allowable size of the log file.
Definition file_logger.h:89
basis::outcome log(const basis::base_string &info, int filter=basis::ALWAYS_PRINT)
writes information to the log file (if the filename is valid).
basis::outcome format_bytes(const basis::byte_array &to_log, int filter=basis::ALWAYS_PRINT)
fancifully formats a stream of bytes "to_log" and sends them into log.
basis::outcome log_bytes(const basis::byte_array &to_log, int filter=basis::ALWAYS_PRINT)
sends a stream of bytes "to_log" without interpretation into the log.
int limit() const
observes the allowable size of the log file.
Definition file_logger.h:87
A base class for a very usable logger with a filter_set and eol awareness.
A logger that sends to the console screen using the standard output device.