Spade
Mini Shell
| Directory:~$ /proc/self/root/usr/lib/python2.7/site-packages/certbot/_internal/ |
| [Home] [System Details] [Kill Me] |
�
���_c@s]dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl
mZddlm
Z
ddlmZddlmZddlmZd Zd
Zeje�Zd�Zd�Zd
�Zdejfd��YZdejjfd��YZdejfd��YZd�Z
d�Z!d�Z"dS(s�Logging utilities for Certbot.
The best way to use this module is through `pre_arg_parse_setup` and
`post_arg_parse_setup`. `pre_arg_parse_setup` configures a minimal
terminal logger and ensures a detailed log is written to a secure
temporary file if Certbot exits before `post_arg_parse_setup` is called.
`post_arg_parse_setup` relies on the parsed command line arguments and
does the full logging setup with terminal and rotating file handling as
configured by the user. Any logged messages before
`post_arg_parse_setup` is called are sent to the rotating file handler.
Special care is taken by both methods to ensure all errors are logged
and properly flushed before program exit.
The `logging` module is useful for recording messages about about what
Certbot is doing under the hood, but do not necessarily need to be shown
to the user on the terminal. The default verbosity is INFO.
The preferred method to display important information to the user is to
use `certbot.display.util` and `certbot.display.ops`.
i����(tprint_functionN(tmessages(terrors(tutil(t constants(toss%(message)ss.%(asctime)s:%(levelname)s:%(name)s:%(message)scCs�t�}|jtjt��|jtj�t|�}t�}|jtjt ��|jt
j�tj�}|jtj�|j
|�|j
|�tjtj�tjt|ddtjkd|j�t_dS(s�Setup
logging before command line arguments are parsed.
Terminal logging is setup using
`certbot._internal.constants.QUIET_LOGGING_LEVEL` so Certbot is as
quiet as
possible. File logging is setup so that logging messages are
buffered in memory. If Certbot exits before `post_arg_parse_setup`
is called, these buffered messages are written to a temporary file.
If Certbot doesn't exit, `post_arg_parse_setup` writes the
messages
to the normal log files.
This function also sets `logging.shutdown` to be called on program
exit which automatically flushes logging handlers and
`sys.excepthook` to properly log/display fatal exceptions.
tdebugs--debugtlog_pathN(tTempHandlertsetFormattertloggingt FormattertFILE_FMTtsetLeveltDEBUGt
MemoryHandlertColoredStreamHandlertCLI_FMTRtQUIET_LOGGING_LEVELt getLoggert
addHandlerRtatexit_registertshutdownt functoolstpartialtpre_arg_parse_except_hooktsystargvtpatht
excepthook(ttemp_handlertmemory_handlertstream_handlertroot_logger((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pytpre_arg_parse_setup.s
cCsSt|dt�\}}tjj|�}tj�}d }}xA|jD]6}t |t
�rh|}qJt |t�rJ|}qJqJWd}|j|�|j
|�|j} |j|�|jdt�|j�| j�|jr�tj}
n|jd}
|j|
�tjd|
�tjd|�tjtd|jd|�t_d S(
s�Setup logging after command line arguments are parsed.
This function assumes `pre_arg_parse_setup` was called earlier and
the root logging configuration has not been modified. A rotating
file logging handler is created and the buffered log messages are
sent to that handler. Terminal logging output is set to the level
requested by the user.
:param certbot.interface.IConfig config: Configuration object
sletsencrypt.logs9Previously configured logging handlers have been
removed!tforcei
sRoot logging level set at %dsSaving debug log to %sRRN(
tsetup_log_file_handlerRRRtdirnameR
RtNonethandlerst
isinstanceRRRt
removeHandlerttargett setTargettflushtTruetclosetquietRRt
verbose_countR
tloggerRtinfoRRtpost_arg_parse_except_hookRR(tconfigtfile_handlert file_pathtlogs_dirR!Rtstderr_handlerthandlertmsgRtlevel((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pytpost_arg_parse_setupTs4
cCs�tj|jd|j�tjj|j|�}y%tjj |ddd|j
�}Wn.tk
r�}tj
tjj|���nX|j�|jtj�tjd|�}|j|�||fS(sSetup
file debug logging.
:param certbot.interface.IConfig config: Configuration object
:param str logfile: basename for the log file
:param str fmt: logging format string
:returns: file handler and absolute path to the log file
:rtype: tuple
i�tmaxBytesiitbackupCounttfmti(Rtset_up_core_dirR7tstrict_permissionsRRtjoinR
R'tRotatingFileHandlertmax_log_backupstIOErrorRtErrortPERM_ERR_FMTtformatt
doRolloverR
RRR (R4tlogfileR?t
log_file_pathR9terrorthandler_formatter((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyR$�s
RcBs#eZdZdd�Zd�ZRS(s6Sends colored logging output
to a stream.
If the specified stream is not a tty, the class works like the
standard `logging.StreamHandler`. Default red_level is
`logging.WARNING`.
:ivar bool colored: True if output should be colored
:ivar bool red_level: The level at which to output
cCsPtt|�j|�|dkr1tjj�n |j�|_tj |_
dS(N(tsuperRt__init__R&RtstderrtisattytcoloredR
tWARNINGt red_level(tselftstream((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyRO�scCsStt|�j|�}|jrO|j|jkrOdjtj|tj f�S|S(s�Formats
the string representation of record.
:param logging.LogRecord record: Record to be formatted
:returns: Formatted, string representation of record
:rtype: str
t(
RNRRHRRtlevelnoRTRBRtANSI_SGR_REDtANSI_SGR_RESET(RUtrecordtout((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyRH�s N(t__name__t
__module__t__doc__R&RORH(((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyR�s
RcBs;eZdZddd�Zd�Zed�Zd�ZRS(s�Buffers
logging messages in memory until the buffer is flushed.
This differs from `logging.handlers.MemoryHandler` in that flushing
only happens when flush(force=True) is called.
i'cCs
tt|�j|d|�dS(NR*(RNRRO(RUR*tcapacity((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyRO�scCs)|j}tt|�j�||_dS(s;Close
the memory handler, but don't set the target to
None.N(R*RNRR.(RUR*((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyR.�s cCs
|rtt|�j�ndS(s�Flush the buffer if force=True.
If force=False, this call is a noop.
:param bool force: True if the buffer should be flushed.
N(RNRR,(RUR#((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyR,�s
cCstS(s�Should the buffer be automatically flushed?
:param logging.LogRecord record: log record to be considered
:returns: False because the buffer should never be auto-flushed
:rtype: bool
(tFalse(RUR[((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pytshouldFlush�s N( R]R^R_R&ROR.RaR,Rb(((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyR�s
RcBs)eZdZd�Zd�Zd�ZRS(sSafely logs messages to
a temporary file.
The file is created with permissions 600. If no log records are sent
to this handler, the temporary file is deleted when the handler is
closed.
:ivar str path: file system path to the temporary log file
cCsktj�|_tjj|jd�|_tj|jdddd�}tt |�j
|�t|_dS(Ntlogtmodetwtchmodi�(
ttempfiletmkdtempt_workdirRRRBRt safe_openRNRROR-t_delete(RURV((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyRO�s
cCs#t|_tt|�j|�dS(slLog the specified logging
record.
:param logging.LogRecord record: Record to be formatted
N(RaRkRNRtemit(RUR[((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyRl�s cCse|j�zI|jj�|jr6tj|j�nt|_tt |�j�Wd|j
�XdS(suClose the handler and the temporary log file.
The temporary log file is deleted if it wasn't used.
N(tacquireRVR.RktshutiltrmtreeRiRaRNRtrelease(RU((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyR.s
(R]R^R_RORlR.(((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyR�s cOs)zt||�Wd|jdt�XdS(sA
simple wrapper around post_arg_parse_except_hook.
The additional functionality provided by this wrapper is the memory
handler will be flushed before Certbot exits. This allows us to
write logging messages to a temporary file if we crashed before
logging was fully configured.
Since sys.excepthook isn't called on SystemExit exceptions, the
memory handler will not be flushed in this case which prevents us
from creating temporary log files when argparse exits because a
command line argument was invalid or -h, --help, or --version was
provided on the command line.
:param MemoryHandler memory_handler: memory handler to flush
:param tuple args: args for post_arg_parse_except_hook
:param dict kwargs: kwargs for post_arg_parse_except_hook
NR#(R3R,R-(Rtargstkwargs((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyRsc Cs2|||f}|s%t|t�rd|tkrNtjd�tjd�ntjdd|�n�tjdd|�t|tj �r�tjt
|��tjd�ntjd�tj|�r�t
|�j
d�\}}}tj|�n.tj||�}tjdj|�j��t|�dS( s!Logs
fatal exceptions and reports them to the user.
If debug is True, the full exception and traceback is shown to the
user, otherwise, it is suppressed. sys.exit is always called with a
nonzero status.
:param type exc_type: type of the raised exception
:param BaseException exc_value: raised exception
:param traceback trace: traceback of where the exception was raised
:param bool debug: True if the traceback should be shown to the user
:param str log_path: path to file or directory containing the log
sExiting due to user request.isExiting abnormally:texc_infosAn
unexpected error occurred:s:: RWN(t
issubclasst ExceptiontKeyboardInterruptR1RLRtexitRRRFtstrRt
is_acme_errort partitiont tracebacktformat_exception_onlyRBtrstriptexit_with_log_path( texc_typet exc_valuettraceRRRst_texc_strtoutput((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyR35s"
cCs\d}tjj|�r.|dj|�7}n|dj|�7}|d7}tj|�dS(s�Print
a message about the log location and exit.
The message is printed to stderr and the program will exit with a
nonzero status.
:param str log_path: path to file or directory containing the log
sPlease see the slogfiles in {0} slogfile '{0}' sfor more
details.N(RRtisdirRHRRw(RR:((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyR~cs
(#R_t
__future__RRR
tlogging.handlersRnRRgR{tacmeRtcertbotRRtcertbot._internalRtcertbot.compatRRRRR]R1R"R<R$t
StreamHandlerRR'RRRR3R~(((s9/usr/lib/python2.7/site-packages/certbot/_internal/log.pyt<module>s2 & .
,- .