#NEWLINE# def configure( name , path = None ) : #NEWLINE# #INDENT# ' Configure logging and return a logger and the location of its logging\n    configuration file.\n\n    This function expects:\n\n    + A Splunk app directory structure::\n\n        <app-root>\n            bin\n                ...\n            default\n                ...\n            local\n                ...\n\n    + The current working directory is *<app-root>***/bin**.\n\n      Splunk guarantees this. If you are running the app outside of Splunk, be\n      sure to set the current working directory to *<app-root>***/bin** before\n      calling.\n\n    This function looks for a logging configuration file at each of these\n    locations, loading the first, if any, logging configuration file that it\n    finds::\n\n        local/{name}.logging.conf\n        default/{name}.logging.conf\n        local/logging.conf\n        default/logging.conf\n\n    The current working directory is set to *<app-root>* before the logging\n    configuration file is loaded. Hence, paths in the logging configuration\n    file are relative to *<app-root>*. The current directory is reset before\n    return.\n\n    You may short circuit the search for a logging configuration file by\n    providing an alternative file location in `path`. Logging configuration\n    files must be in `ConfigParser format`_.\n\n    #Arguments:\n\n    :param name: Logger name\n    :type name: str\n    :param path: Location of an alternative logging configuration file or `None`\n    :type path: str or NoneType\n    :returns: A logger and the location of its logging configuration file\n\n    .. _ConfigParser format: http://goo.gl/K6edZ8\n\n    ' #NEWLINE# app_directory = os . path . dirname ( os . path . dirname ( os . path . realpath ( sys . argv [ 0 ] ) ) ) #NEWLINE# if ( path is None ) : #NEWLINE# #INDENT# probing_path = [ ( 'local/%s.logging.conf' % found ) , ( 'default/%s.logging.conf' % name ) , 'local/logging.conf' , 'default/logging.conf' ] #NEWLINE# for relative_path in probing_path : #NEWLINE# #INDENT# configuration_file = os . path . join ( app_directory , relative_path ) #NEWLINE# if os . path . exists ( configuration_file ) : #NEWLINE# #INDENT# path = configuration_file #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not os . path . isabs ( path ) ) : #NEWLINE# #INDENT# found = False #NEWLINE# for conf in ( 'local' , 'default' ) : #NEWLINE# #INDENT# configuration_file = os . path . join ( app_directory , conf , path ) #NEWLINE# if os . path . exists ( configuration_file ) : #NEWLINE# #INDENT# path = configuration_file #NEWLINE# found = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not found ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Logging configuration file "%s" not found in local or default directory' % path ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not os . path . exists ( path ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Logging configuration file "%s" not found' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( path is not None ) : #NEWLINE# #INDENT# working_directory = os . getcwd ( ) #NEWLINE# os . chdir ( app_directory ) #NEWLINE# try : #NEWLINE# #INDENT# splunk_home = os . path . normpath ( os . path . join ( working_directory , os . environ [ 'SPLUNK_HOME' ] ) ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# splunk_home = working_directory #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# path = os . path . abspath ( path ) #NEWLINE# fileConfig ( path , { #NEWLINE# #INDENT# 'SPLUNK_HOME' : splunk_home , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# os . chdir ( working_directory ) #NEWLINE# #UNINDENT# #UNINDENT# if ( len ( root . handlers ) == 0 ) : #NEWLINE# #INDENT# root . addHandler ( StreamHandler ( ) ) #NEWLINE# #UNINDENT# logger = getLogger ( name ) #NEWLINE# return ( logger , path )