
    ce                     J    d Z ddlmZ ddlmZ  G d dej
                        Zy)z"logging utilities for translation
    )handlers)
_translatec                   *    e Zd ZdZddZd Zd Zd Zy)TranslationHandlera  Handler that translates records before logging them.

    When lazy translation is enabled in the application (see
    :func:`~oslo_i18n.enable_lazy`), the :class:`TranslationHandler`
    uses its locale configuration setting to determine how to
    translate LogRecord objects before forwarding them to the
    logging.Handler.

    When lazy translation is disabled, the message in the LogRecord is
    converted to unicode without any changes and then forwarded to the
    logging.Handler.

    The handler can be configured declaratively in the
    ``logging.conf`` as follows::

        [handlers]
        keys = translatedlog, translator

        [handler_translatedlog]
        class = handlers.WatchedFileHandler
        args = ('/var/log/api-localized.log',)
        formatter = context

        [handler_translator]
        class = oslo_i18n.log.TranslationHandler
        target = translatedlog
        args = ('zh_CN',)

    If the specified locale is not available in the system, the handler will
    log in the default locale.

    Nc                 V    t         j                  j                  | d|       || _        y)zInitialize a TranslationHandler

        :param locale: locale to use for translating messages
        :param target: logging.Handler object to forward
                       LogRecord objects to after translation
        r   )capacitytargetN)r   MemoryHandler__init__locale)selfr   r	   s      //usr/lib/python3/dist-packages/oslo_i18n/log.pyr   zTranslationHandler.__init__;   s&     	''q'H    c                 :    | j                   j                  |       y N)r	   setFormatter)r   fmts     r   r   zTranslationHandler.setFormatterJ   s      %r   c                     |j                   }|j                  }	 | j                  |       ||_         ||_        y # ||_         ||_        w xY wr   )msgargs_translate_and_log_record)r   recordoriginal_msgoriginal_argss       r   emitzTranslationHandler.emitM   sI     zz	(**62%FJ'FK &FJ'FKs	   : A
c                     t        j                  |j                  | j                        |_        t        j                  |j
                  | j                        |_        | j                  j                  |       y r   )r   	translater   r   translate_argsr   r	   r   )r   r   s     r   r   z,TranslationHandler._translate_and_log_recordY   sN    ))&**dkkB

 !//T[[I r   )NN)__name__
__module____qualname____doc__r   r   r   r    r   r   r   r      s    B&
(!r   r   N)r"   loggingr   	oslo_i18nr   r
   r   r#   r   r   <module>r&      s&   "   H!// H!r   