<s> import logging <EOL> import logging . handlers <EOL> import os <EOL> def log ( ) : <EOL> configure_logging ( ) <EOL> return logging . getLogger ( __name__ ) <EOL> def userdata_dir ( ) : <EOL> if os . name == "<STR_LIT>" : <EOL> return os . path . join ( os . getenv ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> else : <EOL> return os . path . join ( os . getenv ( "<STR_LIT>" ) , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def log_dir ( ) : <EOL> return os . path . join ( userdata_dir ( ) , "<STR_LIT>" ) <EOL> def log_file ( ) : <EOL> return os . path . join ( log_dir ( ) , "<STR_LIT>" ) <EOL> def ensure_dir_exists ( dir ) : <EOL> try : <EOL> os . makedirs ( dir ) <EOL> except FileExistsError : <EOL> return <EOL> except Exception as e : <EOL> sublime . error_message ( "<STR_LIT>" + dir + "<STR_LIT>" + str ( e ) ) <EOL> def configure_logging ( ) : <EOL> log = logging . getLogger ( __name__ . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] ) <EOL> if ( len ( log . handlers ) > <NUM_LIT:0> ) : <EOL> return <EOL> print ( "<STR_LIT>" + log_file ( ) ) <EOL> ensure_dir_exists ( log_dir ( ) ) <EOL> handler = logging . handlers . RotatingFileHandler ( log_file ( ) , '<STR_LIT:a>' , <NUM_LIT> , <NUM_LIT:5> , "<STR_LIT:utf-8>" ) <EOL> formatter = logging . Formatter ( '<STR_LIT>' ) <EOL> handler . setFormatter ( formatter ) <EOL> handler . setLevel ( logging . INFO ) <EOL> log . setLevel ( logging . INFO ) <EOL> log . addHandler ( handler ) <EOL> log . info ( "<STR_LIT>" + log . name ) <EOL> log . info ( __name__ ) </s>
