feisty meow concerns codebase
2.140
|
#include <file_logger.h>
Public Types | |
enum | limits { DEFAULT_LOG_FILE_SIZE = 0x10F00D } |
Public Types inherited from basis::array< int > | |
enum | specialc_flags |
the flags specify how the array treats its contents and its length. More... | |
enum | how_to_copy |
enum | shift_directions |
Public Member Functions | |
file_logger () | |
creates a logger without a log file and with the default size limit. More... | |
file_logger (const basis::astring &filename, int limit=DEFAULT_LOG_FILE_SIZE) | |
constructs a logger using the "filename" for output. More... | |
virtual | ~file_logger () |
DEFINE_CLASS_NAME ("file_logger") | |
bool | good () const |
returns true if the logger appears correctly hooked up to a file. More... | |
bool | reopen () |
closes the current file and attempts to reopen it. More... | |
basis::outcome | log (const basis::base_string &info, int filter=basis::ALWAYS_PRINT) |
writes information to the log file (if the filename is valid). More... | |
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. More... | |
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. More... | |
basis::astring | name () const |
observes the filename where logged information is written. More... | |
void | name (const basis::astring &new_name) |
modifies the filename where logged information will be written. More... | |
int | limit () const |
observes the allowable size of the log file. More... | |
void | limit (int new_limit) |
modifies the allowable size of the log file. More... | |
void | flush () |
causes any pending writes to be sent to the output file. More... | |
void | truncate (size_t new_size) |
chops the file to ensure it doesn't go much over the file size limit. More... | |
Public Member Functions inherited from basis::nameable | |
virtual const char * | class_name () const =0 |
Returns the bare name of this class as a constant character pointer. More... | |
Public Member Functions inherited from loggers::filter_set | |
filter_set () | |
Constructs an empty set of filters. More... | |
virtual | ~filter_set () |
filter_set (const structures::set< int > &to_copy) | |
Constructs a copy of the "to_copy" array. More... | |
DEFINE_CLASS_NAME ("filter_set") | |
virtual void | add_filter (int new_filter) |
Adds a member to the filter set. More... | |
virtual void | remove_filter (int old_filter) |
Removes a member from the filter set. More... | |
virtual bool | member (int filter_to_check) |
Returns true if the "filter_to_check" is a member of the filter set. More... | |
virtual void | clear_filters () |
Resets the filter set to be empty. More... | |
Public Member Functions inherited from structures::set< int > | |
set (int num=0, const int *init=NULL_POINTER, basis::un_short flags=basis::array< int >::EXPONE) | |
Constructs a set with "num" elements, copying them from "init". More... | |
~set () | |
Destroys any storage held for the set. More... | |
int | elements () const |
Returns the number of elements in this set. More... | |
bool | empty () const |
Returns true if the set has no elements. More... | |
bool | non_empty () const |
Returns true if the set has some elements. More... | |
void | clear () |
Empties out this set. More... | |
bool | member (const int &to_test) const |
Returns true if the item "to_test" is a member of this set. More... | |
bool | add (const int &to_add) |
Adds a new element "to_add" to the set. More... | |
set & | operator+= (const int &to_add) |
An algebraic operator synonym for add() that operates on the contents. More... | |
set & | operator+= (const set &to_add) |
An algebraic operator synonym for add() that operates on a set. More... | |
bool | remove (const int &to_remove) |
Removes the item "to_remove" from the set. More... | |
set & | operator-= (const int &to_zap) |
An algebraic operator synonym for remove that operates on the contents. More... | |
set & | operator-= (const set &to_zap) |
An algebraic operator synonym for remove that operates on a set. More... | |
set | set_union (const set &union_with) const |
Implements the set union of "this" with "union_with". More... | |
void | unionize (const set &union_with) |
Makes "this" set a union of "this" and "union_with". More... | |
set | operator+ (const set &uw) const |
A synonym for set_union. More... | |
set | intersection (const set &intersect_with) const |
Returns the intersection of "this" with the set in "intersect_with". More... | |
set | operator* (const set &iw) const |
A synonym for intersection. More... | |
set | difference (const set &differ_with) const |
Returns the difference of this with "differ_with". More... | |
void | differentiate (const set &differ_with) |
Makes "this" set equal to the difference of "this" and "differ_with". More... | |
set | operator- (const set &dw) const |
A synonym for difference. More... | |
int | find (const int &to_find) const |
Returns the integer index of the item "to_find" in this set. More... | |
bool | remove_index (int index) |
Zaps the entry at the specified "index". More... | |
Public Member Functions inherited from basis::array< int > | |
DEFINE_CLASS_NAME ("array") | |
array (int number=0, const int *init=NULL_POINTER, int flags=EXPONENTIAL_GROWTH|FLUSH_INVISIBLE) | |
Constructs an array with room for "number" objects. More... | |
array (const array< int > ©_from) | |
copies the contents & sizing information from "copy_from". More... | |
virtual | ~array () |
destroys the memory allocated for the objects. More... | |
void | reset (int number=0, const int *initial_contents=NULL_POINTER) |
Resizes this array and sets the contents from an array of contents. More... | |
array & | operator= (const array< int > ©_from) |
Copies the array in "copy_from" into this. More... | |
int | length () const |
Returns the current reported length of the allocated C array. More... | |
int | last () const |
Returns the last valid element in the array. More... | |
int | flags () const |
Provides the raw flags value, without interpreting what it means. More... | |
bool | exponential () const |
Returns true if this allocator will grow exponentially on resize. More... | |
bool | simple () const |
Reports whether the templated object is a simple type or not. More... | |
const int & | get (int index) const |
Accesses individual objects stored in "this" at the "index" position. More... | |
int & | use (int index) |
A non-constant version of get(); the returned object can be modified. More... | |
const int & | operator[] (int index) const |
Synonym for get that provides the expected array indexing syntax. More... | |
int & | operator[] (int index) |
Synonym for use that provides the expected array indexing syntax. More... | |
outcome | put (int index, const int &to_put) |
Stores an object at the index "index" in the array. More... | |
array | concatenation (const array &to_concatenate) const |
Returns the concatenation of "this" and the array "to_concatenate". More... | |
array | concatenation (const int &to_concatenate) const |
Returns the concatenation of "this" and the object "to_concatenate". More... | |
array & | concatenate (const array &to_concatenate) |
Appends the array "to_concatenate" onto "this" and returns "this". More... | |
array & | concatenate (const int &to_concatenate) |
Appends the object "to_concatenate" onto "this" and returns "this". More... | |
array & | concatenate (const int *to_concatenate, int length) |
Concatenates a C-array "to_concatenate" onto "this" and returns "this". More... | |
array | operator+ (const array &to_cat) const |
Synonym for concatenation. More... | |
array | operator+ (const int &to_concatenate) const |
Synonym for concatenation. More... | |
array & | operator+= (const array &to_concatenate) |
Synonym for concatenate that modifies "this". More... | |
array & | operator+= (const int &to_concatenate) |
Synonym for concatenate that modifies "this". More... | |
const int * | observe () const |
Returns a pointer to the underlying C array of data. More... | |
int * | access () |
A non-constant access of the underlying C-array. BE REALLY CAREFUL. More... | |
void | swap_contents (array< int > &other) |
Exchanges the contents of "this" and "other". More... | |
void | snarf (array &new_contents) |
Drops "this" array's contents into the dustbin and uses "new_contents". More... | |
array | subarray (int start, int end) const |
Returns the array segment between the indices "start" and "end". More... | |
outcome | insert (int index, int new_indices) |
Adds "new_indices" new positions for objects into the array at "index". More... | |
outcome | overwrite (int index, const array &write_with, int count=-1) |
Stores the array "write_with" into the current array at the "index". More... | |
outcome | stuff (int length, int *to_stuff) const |
Copies at most "length" elements from this into the array "to_stuff". More... | |
outcome | resize (int new_size, how_to_copy way=NEW_AT_END) |
Changes the size of the C array to "new_size". More... | |
outcome | zap (int start, int end) |
Deletes from "this" the objects inclusively between "start" and "end". More... | |
outcome | shrink () |
Cuts loose any allocated space that is beyond the real length. More... | |
outcome | retrain (int new_size, const int *to_copy) |
Resizes the C array and stuffs it with the contents in "to_copy". More... | |
void | shift_data (shift_directions where) |
The valid portion of the array is moved to the left or right. More... | |
int | internal_real_length () const |
Gritty Internal: the real allocated length. More... | |
int | internal_offset () const |
Gritty Internal: the offset from real start to stored data. More... | |
const int * | internal_block_start () const |
Gritty Internal: constant peek at the real allocated pointer. More... | |
int * | internal_block_start () |
Gritty Internal: the real allocated pointer made accessible. More... | |
int *const * | internal_offset_mem () const |
Gritty Internal: the start of the actual stored data. More... | |
Public Member Functions inherited from loggers::eol_aware | |
virtual textual::parser_bits::line_ending | eol () |
observes how line endings are to be printed. More... | |
virtual void | eol (textual::parser_bits::line_ending to_set) |
modifies how line endings are to be printed. More... | |
virtual basis::astring | get_ending () |
returns a string for the current ending. More... | |
virtual void | get_ending (basis::astring &to_end) |
appends a string for the current ending to "to_end". More... | |
Static Public Member Functions | |
static basis::astring | log_file_for_app_name () |
returns a log file name for file_logger based on the program name. More... | |
Definition at line 37 of file file_logger.h.
Enumerator | |
---|---|
DEFAULT_LOG_FILE_SIZE | this just defines the default for the log file size. |
Definition at line 53 of file file_logger.h.
loggers::file_logger::file_logger | ( | ) |
creates a logger without a log file and with the default size limit.
the log file name can be changed using filename().
Definition at line 60 of file file_logger.cpp.
References name().
loggers::file_logger::file_logger | ( | const basis::astring & | filename, |
int | limit = DEFAULT_LOG_FILE_SIZE |
||
) |
constructs a logger using the "filename" for output.
there will be no logging if the "filename" is empty. the "limit" specifies how large the log file can be (in bytes).
Definition at line 69 of file file_logger.cpp.
References name().
|
virtual |
Definition at line 80 of file file_logger.cpp.
References basis::WHACK().
loggers::file_logger::DEFINE_CLASS_NAME | ( | "file_logger" | ) |
void loggers::file_logger::flush | ( | ) |
causes any pending writes to be sent to the output file.
Definition at line 135 of file file_logger.cpp.
References filesystem::byte_filer::flush().
Referenced by log(), and log_bytes().
outcome loggers::file_logger::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.
Definition at line 234 of file file_logger.cpp.
References filesystem::byte_filer::good(), basis::array< contents >::length(), log(), and loggers::filter_set::member().
bool loggers::file_logger::good | ( | ) | const |
returns true if the logger appears correctly hooked up to a file.
note that we don't open the file when file_logger is constructed; it is only opened once the first logging is attempted.
Definition at line 121 of file file_logger.cpp.
References filesystem::byte_filer::good().
|
inline |
observes the allowable size of the log file.
Definition at line 87 of file file_logger.h.
|
inline |
modifies the allowable size of the log file.
Definition at line 89 of file file_logger.h.
|
virtual |
writes information to the log file (if the filename is valid).
the "filter" value is checked to see if it is in the current set of allowed filters. a value of zero is always printed. if the filename() has not been set, then the information is lost.
Implements basis::base_logger.
Definition at line 177 of file file_logger.cpp.
References flush(), filesystem::byte_filer::good(), basis::astring::length(), basis::base_string::length(), loggers::filter_set::member(), basis::base_string::observe(), basis::astring::s(), filesystem::byte_filer::tell(), truncate(), and filesystem::byte_filer::write().
Referenced by format_bytes(), and loggers::combo_logger::log().
outcome loggers::file_logger::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.
if the "filter" is not enabled, then the info is just tossed out.
Definition at line 208 of file file_logger.cpp.
References flush(), filesystem::byte_filer::good(), basis::array< contents >::length(), loggers::filter_set::member(), basis::array< contents >::observe(), filesystem::byte_filer::tell(), truncate(), and filesystem::byte_filer::write().
|
static |
returns a log file name for file_logger based on the program name.
for a program named myapp.exe, this will be in the form: {logging_dir}/myapp.log
Definition at line 87 of file file_logger.cpp.
References filesystem::filename::rootname().
astring loggers::file_logger::name | ( | ) | const |
observes the filename where logged information is written.
Definition at line 129 of file file_logger.cpp.
Referenced by file_logger(), reopen(), and truncate().
void loggers::file_logger::name | ( | const basis::astring & | new_name | ) |
modifies the filename where logged information will be written.
if "new_name" is blank, then the logged information will not be saved.
Definition at line 108 of file file_logger.cpp.
bool loggers::file_logger::reopen | ( | ) |
closes the current file and attempts to reopen it.
this is handy if the original opening of the file failed.
Definition at line 93 of file file_logger.cpp.
References name().
void loggers::file_logger::truncate | ( | size_t | new_size | ) |
chops the file to ensure it doesn't go much over the file size limit.
this can be used externally also, but be careful with it.
// our synchronization scheme allows us to use this inter-application // lock; the logger's own lock is always acquired first. no one else can // grab the "file_lock", so no deadlocks.
rendezvous file_lock(*_filename + "_trunclock"); if (!file_lock.healthy()) { critical_events::write_to_critical_events((astring("could not create " "lock for ") + *_filename).s()); return; } // waiting forever until the file lock succeeds. as long as there are // no deadlocks permitted, then this shouldn't be too dangerous... bool got_lock = file_lock.lock(rendezvous::ENDLESS_WAIT); if (!got_lock) { critical_events::write_to_critical_events((astring("could not acquire " "lock for ") + *_filename).s()); return; }
file_lock.unlock();
file_lock.unlock(); // repeal the process-wide lock.
Definition at line 265 of file file_logger.cpp.
References filesystem::byte_filer::eof(), filesystem::byte_filer::good(), loggers::MAXIMUM_BUFFER_SIZE, name(), filesystem::byte_filer::read(), basis::astring::s(), filesystem::byte_filer::seek(), loggers::static_chaos(), filesystem::byte_filer::tell(), unlink, basis::WHACK(), and filesystem::byte_filer::write().
Referenced by log(), and log_bytes().