<s> import Queue <EOL> import logging <EOL> import thread <EOL> from luigi_gcloud . gcore import get_default_client <EOL> def logger ( logging_api , queue ) : <EOL> while True : <EOL> entry = queue . get ( ) <EOL> logging_api . entries ( ) . write ( <EOL> body = { <EOL> "<STR_LIT>" : [ <EOL> entry <EOL> ] <EOL> } <EOL> ) . execute ( ) <EOL> queue . task_done ( ) <EOL> class CloudLoggingHandler ( logging . Handler ) : <EOL> def __init__ ( self ) : <EOL> logging . Handler . __init__ ( self ) <EOL> self . name = "<STR_LIT>" <EOL> client = get_default_client ( ) <EOL> self . project_id = self . project_id = client . project_id ( ) <EOL> http = client . http_authorized ( ) <EOL> self . logging_api = client . logging_api ( http ) <EOL> self . queue = Queue . Queue ( ) <EOL> thread . start_new_thread ( logger , ( self . logging_api , self . queue ) ) <EOL> def emit ( self , record ) : <EOL> self . queue . put ( { <EOL> "<STR_LIT>" : record . levelname , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : record . name , <EOL> "<STR_LIT>" : record . module , <EOL> "<STR_LIT:message>" : record . getMessage ( ) <EOL> } , <EOL> "<STR_LIT>" : "<STR_LIT>" + self . project_id + "<STR_LIT>" + self . name , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> } } ) </s>
