[racket-dev] Request for max-log-level

From: Tobias Hammer (tobias.hammer at dlr.de)
Date: Thu Feb 16 08:53:33 EST 2012

Hi,

i have to synchronize the log levels of a racket logger and an external  
logging
system. Therefore i need the information what the highest logging level of  
a
logger is to already discard any messages in the external system that have  
no
receiver.
Because there is, as far as i know, no possibility to get a notification  
whenever
the internal accepted level changes i have to synchronize pretty often.  
This is
currently only possible by cycling through all levels and check via  
log-level?
which is cumbersome and, at least for my needs, too slow.
Would it be possible to add a function that returns the current maximum  
level of
a logger? The needed information is already stored in  
Scheme_Logger::want_level
but there is no accessor. The following addition (excl. function  
registration)
to error.c would do the job:

static Scheme_Object *
max_log_level(int argc, Scheme_Object *argv[])
{
   Scheme_Logger *logger;
   Scheme_Object *result;

   if (!SAME_TYPE(SCHEME_TYPE(argv[0]), scheme_logger_type))
     scheme_wrong_type("max-log-level", "logger", 0, argc, argv);
   logger = (Scheme_Logger *)argv[0];

   if (logger->local_timestamp < *logger->timestamp)
     update_want_level(logger);

   switch (logger->want_level)
   {
   case SCHEME_LOG_FATAL: result = fatal_symbol; break;
   case SCHEME_LOG_ERROR: result = error_symbol; break;
   case SCHEME_LOG_WARNING: result = warning_symbol; break;
   case SCHEME_LOG_INFO:  result = info_symbol; break;
   case SCHEME_LOG_DEBUG: result = debug_symbol; break;
   default: result = scheme_false;
   }

   return result;
}

(No patch because i completely messed up with compiled startup and  
expected primitive
count, even after following instructions in schminc.h :( )

Tobias

Posted on the dev mailing list.