critical_events.cpp

Go to the documentation of this file.
00001 #ifndef CRITICAL_EVENTS_IMPLEMENTATION_FILE
00002 #define CRITICAL_EVENTS_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : critical_events                                                   *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1989-$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 "critical_events.h"
00019 #include "path_configuration.h"
00020 
00021 #include <basis/function.h>
00022 #include <basis/istring.h>
00023 #include <basis/log_base.h>
00024 #include <basis/mutex.h>
00025 #include <basis/portable.h>
00026 #include <data_struct/static_memory_gremlin.h>
00027 
00028 #include <stdio.h>
00029 
00030 SAFE_STATIC(istring_object, critical_events::hidden_critical_events_dir, )
00031   // define the function that holds the directory string.
00032 
00033 istring default_critical_location()
00034 {
00035   // ensure that the critical events function logs to the appropriate place.
00036   return path_configuration::get_logging_directory();
00037 }
00038 
00039 SAFE_STATIC(mutex, __critical_event_dir_lock, )
00040 
00041 istring critical_events::critical_events_directory()
00042 {
00043   static bool initted = false;
00044   if (!initted) {
00045     auto_synchronizer l(__critical_event_dir_lock());
00046     if (!initted) {
00047       set_critical_events_directory(default_critical_location());
00048       initted = true;
00049     }
00050   }
00051   return hidden_critical_events_dir();
00052 }
00053 
00054 void critical_events::set_critical_events_directory(const istring &directory)
00055 { hidden_critical_events_dir() = directory; }
00056 
00057 void critical_events::write_to_critical_events(const char *to_write)
00058 {
00059   istring filename = critical_events_directory();
00060   filename += "/runtime_issues.log";
00061   FILE *errfile = fopen(filename.s(), "ab");
00062   if (errfile) {
00063     istring app_name = portable::application_name();
00064     int indy = app_name.find('/', app_name.end(), true);
00065     if (non_negative(indy)) app_name.zap(0, indy);
00066     indy = app_name.find('\\', app_name.end(), true);
00067     if (non_negative(indy)) app_name.zap(0, indy);
00068     fprintf(errfile, "%s [%s]:%s", utility::timestamp(true, true).s(),
00069         app_name.s(), log_base::platform_ending());
00070     fprintf(errfile, "%s%s", to_write, log_base::platform_ending());
00071     fclose(errfile);
00072   }
00073 }
00074 
00075 
00076 #endif //CRITICAL_EVENTS_IMPLEMENTATION_FILE
00077 

Generated on Thu Nov 20 04:29:03 2008 for HOOPLE Libraries by  doxygen 1.5.1