Changeset 16427

Show
Ignore:
Timestamp:
05/21/08 23:45:35 (7 months ago)
Author:
piotras
Message:

Set and remove log handler so it's associated per request.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/branch-1-9/midgard/apis/php5/midgard.c

    r16045 r16427  
    447447        MidgardConnection *mgd = (MidgardConnection*) userdata; 
    448448        gchar *level_ad = NULL; 
    449         guint mlevel = midgard_connection_get_loglevel(mgd); 
     449        guint mlevel = 0; 
     450        if(mgd) 
     451                mlevel = midgard_connection_get_loglevel(mgd); 
    450452         
    451453        g_assert(msg != NULL); 
     
    502504        }        
    503505 
    504         if (mlevel >= level) { 
     506        if (mlevel >= level && mgd != NULL) { 
    505507 
    506508                midgard_error_default_log( 
    507509                                domain, level, msg, MIDGARD_CONNECTION(mgd)); 
    508510        } 
    509  
    510         /* 
    511          if (mgd->loglevel >= level) { 
    512                  
    513                 if (mgd->logfile == NULL) {      
    514                         logfile = stderr; 
    515                 } else { 
    516                         logfile = fopen(mgd->logfile, "a"); 
    517                         if (logfile == NULL) { 
    518                                 logfile = stderr; 
    519                                 php_error(E_WARNING,  
    520                                                 "Could not open logfile '%s', using stderr",  
    521                                                 mgd->logfile); 
    522                         }                        
    523                 } 
    524                 fno = fileno(logfile);           
    525                 if (fno != 2) flock(fno, LOCK_EX);               
    526                 fprintf(logfile, "%s ", domain != NULL ? domain : "midgard-core"); 
    527                 fprintf(logfile, "(pid:%ld):", (unsigned long)getpid()); 
    528                 fprintf(logfile, "(%s):", level_ad); 
    529                 fprintf(logfile, "  %s\n", msg); 
    530                 fflush(logfile); 
    531                 if (fno != 2) flock(fno, LOCK_UN); 
    532                 if (fno != 2) fclose(logfile); 
    533         } 
    534         */ 
    535511} 
    536512 
     
    604580 
    605581        global_loghandler = 
    606                 g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_MASK, 
     582                g_log_set_handler("midgard-core", G_LOG_LEVEL_MASK, 
    607583                                midgard_error_default_log, NULL);  
    608584         
     
    734710        REGISTER_LONG_CONSTANT("MGD_ERR_OBJECT_IMPORTED", MGD_ERR_OBJECT_IMPORTED, CONST_CS | CONST_PERSISTENT); 
    735711        REGISTER_LONG_CONSTANT("MGD_ERR_MISSED_DEPENDENCE", MGD_ERR_MISSED_DEPENDENCE, CONST_CS | CONST_PERSISTENT); 
     712         
     713        g_log_remove_handler("midgard-core", global_loghandler); 
     714        global_loghandler = 0; 
    736715 
    737716        return SUCCESS; 
     
    752731{ 
    753732        g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); 
     733         
    754734        if (SG(server_context)) { 
    755735                MGDG(rcfg) = mgd_php_bug_workaround_get_rcfg(); 
     
    793773                mgd_handle_singleton_set(mgd_handle()->_mgd); 
    794774 
    795                 guint loghandler = 
    796                         g_log_set_handler(G_LOG_DOMAIN
     775                global_loghandler = 
     776                        g_log_set_handler("midgard-core"
    797777                                        G_LOG_LEVEL_MASK, 
    798778                                        php_midgard_log_errors, 
     
    800780 
    801781                midgard_connection_set_loghandler( 
    802                                 mgd_handle_singleton_get(), loghandler); 
    803         } 
    804  
     782                                mgd_handle_singleton_get(), global_loghandler); 
     783        } 
     784         
    805785        /* Initialize closure hash */ 
    806786        php_midgard_gobject_closure_hash_new(); 
     
    812792PHP_RSHUTDOWN_FUNCTION(midgard) 
    813793{ 
     794        /* Remove midgard loghandler. This might be valid in web environment,  
     795         * and might be not valid in cli. Midgard connection object might be  
     796         * already unrefed here. */ 
     797        if(global_loghandler) 
     798                g_log_remove_handler("midgard-core", global_loghandler); 
     799 
     800        /* FIXME, at least MidgardTypeHolder should be passed here instead of NULL */ 
     801        global_loghandler = 
     802                g_log_set_handler("midgard-core", 
     803                                G_LOG_LEVEL_MASK, 
     804                                php_midgard_log_errors, NULL); 
     805 
     806        g_debug("MIDGARD REQUEST END"); 
     807 
    814808        midgard_request_config *rcfg = mgd_rcfg(); 
    815809        midgard *mgd = mgd_handle(); 
     
    847841        php_midgard_gobject_closure_hash_free(); 
    848842 
    849         g_debug("MIDGARD REQUEST END"); 
     843        g_debug("MIDGARD REQUEST END - SUCCESS"); 
     844 
     845        g_log_remove_handler("midgard-core", global_loghandler); 
    850846 
    851847        return SUCCESS;