Roxen.git / server / base_server / module.pike

version» Context lines:

Roxen.git/server/base_server/module.pike:1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2009, Roxen IS. - // $Id: module.pike,v 1.245 2012/01/23 12:50:52 grubba Exp $ + // $Id$      #include <module_constants.h>   #include <module.h>   #include <request_trace.h>      constant __pragma_save_parent__ = 1;      // Tell Pike.count_memory this is global.   constant pike_cycle_depth = 0;   
Roxen.git/server/base_server/module.pike:38:    [_my_configuration, _module_local_identifier] = init_info;    return _my_configuration->name + "/" + _module_local_identifier;    }   #ifdef DEBUG    else    error ("Got invalid bootstrap info for module: %O\n", init_info);   #endif    }();   protected mapping _api_functions = ([]);    + class ModuleJSONLogger { +  inherit Logger.BaseJSONLogger; +  +  void create(object parent_config) { +  string name = combine_path_unix(parent_config->json_logger->logger_name, +  module_local_id()); +  ::create(name, UNDEFINED, parent_config->json_logger); +  } + } +  + // Module local JSON logger + private ModuleJSONLogger json_logger; +    string|array(string) module_creator;   string module_url;   RXML.TagSet module_tag_set;      /* These functions exist in here because otherwise the messages in the    * event log do not always end up in the correct module/configuration.    * And the reason for that is that if the messages are logged from    * subclasses in the module, the DWIM in roxenlib.pike cannot see that    * they are logged from a module. This solution is not really all that    * beautiful, but it works. :-)
Roxen.git/server/base_server/module.pike:71:    void|mapping(string:mixed) info)   //! Log an event. See @[Configuration.log_event] for details.   //!   //! @[facility] may be zero. The local module identifier as returned   //! by @[module_local_id] is used as facility in that case.   {    _my_configuration->log_event (facility || _module_local_identifier,    action, resource, info);   }    + void json_log_trace(string|mapping log_msg) { json_log_with_level(log_msg, Logger.BaseJSONLogger.TRACE); } + void json_log_debug(string|mapping log_msg) { json_log_with_level(log_msg, Logger.BaseJSONLogger.DBG); } + void json_log_info (string|mapping log_msg) { json_log_with_level(log_msg, Logger.BaseJSONLogger.INFO); } + void json_log_warn (string|mapping log_msg) { json_log_with_level(log_msg, Logger.BaseJSONLogger.WARN); } + void json_log_error(string|mapping log_msg) { json_log_with_level(log_msg, Logger.BaseJSONLogger.ERROR); } + void json_log_fatal(string|mapping log_msg) { json_log_with_level(log_msg, Logger.BaseJSONLogger.FATAL); } +  + // Helper method to force a specific logging level + void json_log_with_level(string|mapping log_msg, int level) { +  if (stringp(log_msg)) { +  log_msg = ([ +  "msg" : log_msg, +  ]); +  } +  log_msg->level = level; +  json_log(log_msg); + } +  + // Log a message more or less verbatim via the JSON logger infrastructure + void json_log(string|mapping log_msg) { +  if (stringp(log_msg)) { +  log_msg = ([ +  "msg" : log_msg, +  ]); +  } +  +  if (json_logger && functionp(json_logger->log)) { +  json_logger->log(log_msg); +  } + } +    string module_identifier()   //! Returns a string that uniquely identifies this module instance   //! within the server. The identifier is the same as   //! @[Roxen.get_module] and @[Roxen.get_modname] handles.   {    return _module_identifier;   }      string module_local_id()   //! Returns a string that uniquely identifies this module instance
Roxen.git/server/base_server/module.pike:196:   //! belongs to.   {    return _my_configuration;   }      final void set_configuration(Configuration c)   {    if(_my_configuration && _my_configuration != c)    error("set_configuration() called twice.\n");    _my_configuration = c; +  +  // if configuration changes, we should reinitialize our JSON logger too! +  json_logger = ModuleJSONLogger(_my_configuration);   }      void set_module_creator(string|array(string) c)   //! Set the name and optionally email address of the author of the   //! module. Names on the format "author name <author_email>" will   //! end up as links on the module's information page in the admin   //! interface. In the case of multiple authors, an array of such   //! strings can be passed.   {    module_creator = c;