o c @sZddlmZddlZddlZddlZddlZdZdddZddd Zdd d Z d d Z dS))absolute_importNz;%(asctime)s %(levelname)-8s [%(threadName)-10s] %(message)sinfocCsR|jddddddd}|r|d|7}|jd d d ||d |jd |dddS)z?Add common logging-related CLI options to the given arg parser.z-qz--quietF store_truez"Do not log to the standard output.)defaultactionhelpz)The directory in which to write log filesz (default: {!r}).z-lz --log-dirFILE)metavarrrz --log-levelz/One of debug, info, warning, error or critical.)rrN) add_optionformat)parserlevellogdir logdirhelpr7/usr/lib/python3/dist-packages/landscape/lib/logging.pyadd_cli_options s   rFcCsV|dur tjtjd}t|}tt |||t t |s$tj ndt S)z3Given a log dir, set up logging for an application.Nr) ospathbasenamesysargvlogging getLevelNameupper _init_logging getLogger FormatterFORMATstdout)rr prognamequietrrrinit_app_loggings r"c Cst||tj|st|tj||d}t|g}|r)|t ||D] }| || |q+dS)Nz.log) setLevelrrexistsmakedirsjoinr FileHandlerappend StreamHandler addHandler setFormatter) loggerr rlogname formatterrfilenamehandlershandlerrrrr+s     rc CsdtjD]%}t|tjr*|z|jt|j |j |_W| q| wqt ddS)z This closes and reopens the underlying files in the logging module's root logger. If called after logrotate (or something similar) has moved the old log file out of the way, this will start writing to a new new log file... zLandscape Logs rotatedN) rrr0 isinstancer'acquirestreamcloseopen baseFilenamemodereleaser)r1rrr rotate_logs?s  r:)rN)rNF)N) __future__rrros.pathrrrr"rr:rrrrs