00001 #ifndef CONSOLE_LOGGER_IMPLEMENTATION_FILE 00002 #define CONSOLE_LOGGER_IMPLEMENTATION_FILE 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : console_logger * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 2000-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include "console_logger.h" 00019 00020 #include <basis/istring.h> 00021 #include <basis/mutex.h> 00022 00023 #include <stdio.h> 00024 00025 console_logger::console_logger(bool to_stderr) 00026 : _to_stderr(to_stderr) 00027 {} 00028 00029 console_logger::~console_logger() {} 00030 00031 outcome console_logger::log(const istring &info, int filter) 00032 { 00033 FILE *log_to = stdout; 00034 if (_to_stderr) log_to = stderr; 00035 if (member(filter)) { 00036 // format the output with %s to ensure we get all characters, rather 00037 // than having some get interpreted if we used info as the format spec. 00038 fprintf(log_to, "%s", info.s()); 00039 // send the EOL char if the style is appropriate for that. 00040 if (eol() != NO_ENDING) fprintf(log_to, (char *)get_ending().s()); 00041 // write immediately to avoid lost output on crash. 00042 fflush(log_to); 00043 } 00044 return common::OKAY; 00045 } 00046 00047 #ifndef OMIT_PROGRAM_WIDE_LOGGER 00048 log_base *set_PW_logger_for_console(bool standard_error) 00049 { 00050 console_logger *new_pw = new console_logger(standard_error); 00051 return retask_program_wide_logger(new_pw); 00052 } 00053 #endif 00054 00055 #endif //CONSOLE_LOGGER_IMPLEMENTATION_FILE 00056
1.5.1