本文整理汇总了Python中logging.getLogger方法的典型用法代码示例。如果您正苦于以下问题:Python logging.getLogger方法的具体用法?Python logging.getLogger怎么用?Python logging.getLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging.getLogger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def get_logger(cls,logger_name,create_file=False):
# create logger for prd_ci
log = logging.getLogger(logger_name)
log.setLevel(level=logging.INFO)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
if create_file:
# create file handler for logger.
fh = logging.FileHandler('SPOT.log')
fh.setLevel(level=logging.DEBUG)
fh.setFormatter(formatter)
# reate console handler for logger.
ch = logging.StreamHandler()
ch.setLevel(level=logging.DEBUG)
ch.setFormatter(formatter)
# add handlers to logger.
if create_file:
log.addHandler(fh)
log.addHandler(ch)
return log
示例2: init_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def init_logging(log_file=None, append=False, console_loglevel=logging.INFO):
"""Set up logging to file and console."""
if log_file is not None:
if append:
filemode_val = 'a'
else:
filemode_val = 'w'
logging.basicConfig(level=logging.DEBUG,
format="%(asctime)s %(levelname)s %(threadName)s %(name)s %(message)s",
# datefmt='%m-%d %H:%M',
filename=log_file,
filemode=filemode_val)
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(console_loglevel)
# set a format which is simpler for console use
formatter = logging.Formatter("%(message)s")
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
global LOG
LOG = logging.getLogger(__name__)
示例3: setup_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def setup_logging():
# Setup root logger
logger = logging.getLogger('drydock')
logger.setLevel('DEBUG')
ch = logging.StreamHandler()
formatter = logging.Formatter(
'%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s - %(message)s'
)
ch.setFormatter(formatter)
logger.addHandler(ch)
# Specalized format for API logging
logger = logging.getLogger('drydock.control')
logger.propagate = False
formatter = logging.Formatter(
"%(asctime)s - %(levelname)s - %(user)s - %(req_id)s"
" - %(external_ctx)s - %(end_user)s - %(message)s"
)
ch = logging.StreamHandler()
ch.setFormatter(formatter)
logger.addHandler(ch)
示例4: convert
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def convert(netflow, tmpdir, opts='', prefix=None):
'''
Convert `nfcapd` file to a comma-separated output format.
:param netflow : Path of binary file.
:param tmpdir : Path of local staging area.
:param opts : A set of options for `nfdump` command.
:param prefix : If `prefix` is specified, the file name will begin with that;
otherwise, a default `prefix` is used.
:returns : Path of CSV-converted file.
:rtype : ``str``
:raises OSError: If an error occurs while executing the `nfdump` command.
'''
logger = logging.getLogger('SPOT.INGEST.FLOW.PROCESS')
with tempfile.NamedTemporaryFile(prefix=prefix, dir=tmpdir, delete=False) as fp:
command = COMMAND.format(netflow, opts, fp.name)
logger.debug('Execute command: {0}'.format(command))
Util.popen(command, raises=True)
return fp.name
示例5: convert
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def convert(logfile, tmpdir, opts='', prefix=None):
'''
Copy log file to the local staging area.
:param logfile: Path of log file.
:param tmpdir : Path of local staging area.
:param opts : A set of options for the `cp` command.
:param prefix : If `prefix` is specified, the file name will begin with that;
otherwise, a default `prefix` is used.
:returns : Path of log file in local staging area.
:rtype : ``str``
'''
logger = logging.getLogger('SPOT.INGEST.PROXY.PROCESS')
with tempfile.NamedTemporaryFile(prefix=prefix, dir=tmpdir, delete=False) as fp:
command = COMMAND.format(opts, logfile, fp.name)
logger.debug('Execute command: {0}'.format(command))
Util.popen(command, raises=True)
return fp.name
示例6: ingest_file
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def ingest_file(file,message_size,topic,kafka_servers):
logger = logging.getLogger('SPOT.INGEST.PROXY.{0}'.format(os.getpid()))
try:
message = ""
logger.info("Ingesting file: {0} process:{1}".format(file,os.getpid()))
with open(file,"rb") as f:
for line in f:
message += line
if len(message) > message_size:
KafkaProducer.SendMessage(message, kafka_servers, topic, 0)
message = ""
#send the last package.
KafkaProducer.SendMessage(message, kafka_servers, topic, 0)
rm_file = "rm {0}".format(file)
Util.execute_cmd(rm_file,logger)
logger.info("File {0} has been successfully sent to Kafka Topic: {1}".format(file,topic))
except Exception as err:
logger.error("There was a problem, please check the following error message:{0}".format(err.message))
logger.error("Exception: {0}".format(err))
示例7: convert
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def convert(pcap, tmpdir, opts='', prefix=None):
'''
Convert `pcap` file to a comma-separated output format.
:param pcap : Path of binary file.
:param tmpdir : Path of local staging area.
:param opts : A set of options for `tshark` command.
:param prefix : If `prefix` is specified, the file name will begin with that;
otherwise, a default `prefix` is used.
:returns : Path of CSV-converted file.
:rtype : ``str``
:raises OSError: If an error occurs while executing the `tshark` command.
'''
logger = logging.getLogger('SPOT.INGEST.DNS.PROCESS')
with tempfile.NamedTemporaryFile(prefix=prefix, dir=tmpdir, delete=False) as fp:
command = COMMAND.format(pcap, opts, fp.name)
logger.debug('Execute command: {0}'.format(command))
Util.popen(command, raises=True)
return fp.name
示例8: call
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def call(cls, cmd, shell=False):
'''
Run command with arguments, wait to complete and return ``True`` on success.
:param cls: The class as implicit first argument.
:param cmd: Command string to be executed.
:returns : ``True`` on success, otherwise ``None``.
:rtype : ``bool``
'''
logger = logging.getLogger('SPOT.INGEST.COMMON.UTIL')
logger.debug('Execute command: {0}'.format(cmd))
try:
subprocess.call(cmd, shell=shell)
return True
except Exception as exc:
logger.error('[{0}] {1}'.format(exc.__class__.__name__, exc.message))
示例9: _initialize_members
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def _initialize_members(self, topic, server, port, zk_server, zk_port, partitions):
# get logger isinstance
self._logger = logging.getLogger("SPOT.INGEST.KafkaProducer")
# kafka requirements
self._server = server
self._port = port
self._zk_server = zk_server
self._zk_port = zk_port
self._topic = topic
self._num_of_partitions = partitions
self._partitions = []
self._partitioner = None
self._kafka_brokers = '{0}:{1}'.format(self._server, self._port)
# create topic with partitions
self._create_topic()
self._kafka_conf = self._producer_config(self._kafka_brokers)
self._p = Producer(**self._kafka_conf)
示例10: deserialize
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def deserialize(rawbytes):
'''
Deserialize given bytes according to the supported Avro schema.
:param rawbytes: A buffered I/O implementation using an in-memory bytes buffer.
:returns : List of ``str`` objects, extracted from the binary stream.
:rtype : ``list``
'''
decoder = avro.io.BinaryDecoder(io.BytesIO(rawbytes))
reader = avro.io.DatumReader(avro.schema.parse(AVSC))
try: return reader.read(decoder)[list.__name__]
except Exception as exc:
logging.getLogger('SPOT.INGEST.COMMON.SERIALIZER')\
.error('[{0}] {1}'.format(exc.__class__.__name__, exc.message))
return []
示例11: serialize
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def serialize(value):
'''
Convert a ``list`` object to an avro-encoded format.
:param value: List of ``str`` objects.
:returns : A buffered I/O implementation using an in-memory bytes buffer.
:rtype : ``str``
'''
writer = avro.io.DatumWriter(avro.schema.parse(AVSC))
rawbytes = io.BytesIO()
try:
writer.write({ list.__name__: value }, avro.io.BinaryEncoder(rawbytes))
return rawbytes
except avro.io.AvroTypeException:
logging.getLogger('SPOT.INGEST.COMMON.SERIALIZER')\
.error('The type of ``{0}`` is not supported by the Avro schema.'
.format(type(value).__name__))
return None
示例12: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def __init__(self, url, mutual_auth, cert=None, verify='true', **kwargs):
self._logger = logging.getLogger("SPOT.INGEST.HDFS_client")
session = Session()
if verify == 'true':
self._logger.info('SSL verification enabled')
session.verify = True
if cert is not None:
self._logger.info('SSL Cert: ' + cert)
if ',' in cert:
session.cert = [path.strip() for path in cert.split(',')]
else:
session.cert = cert
elif verify == 'false':
session.verify = False
super(SecureKerberosClient, self).__init__(url, mutual_auth, session=session, **kwargs)
示例13: get_client
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def get_client(user=None):
# type: (object) -> Client
logger = logging.getLogger('SPOT.INGEST.HDFS.get_client')
hdfs_nm, hdfs_port, hdfs_user = Config.hdfs()
conf = {'url': '{0}:{1}'.format(hdfs_nm, hdfs_port)}
if Config.ssl_enabled():
ssl_verify, ca_location, cert, key = Config.ssl()
conf.update({'verify': ssl_verify.lower()})
if cert:
conf.update({'cert': cert})
if Config.kerberos_enabled():
krb_conf = {'mutual_auth': 'OPTIONAL'}
conf.update(krb_conf)
# TODO: possible user parameter
logger.info('Client conf:')
for k,v in conf.iteritems():
logger.info(k + ': ' + v)
client = SecureKerberosClient(**conf)
return client
示例14: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def __init__(self,config,logger=None):
self._logger = logging.getLogger('OA.IANA') if logger else Util.get_logger('OA.IANA',create_file=False)
if COL_CLASS in config:
self._qclass_file_path = config[COL_CLASS]
if COL_QTYPE in config:
self._qtype_file_path = config[COL_QTYPE]
if COL_RCODE in config:
self._rcode_file_path = config[COL_RCODE]
if COL_PRESP in config:
self._http_rcode_file_path = config[COL_PRESP]
self._qclass_dict = {}
self._qtype_dict = {}
self._rcode_dict = {}
self._http_rcode_dict = {}
self._init_dicts()
示例15: urlParser
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLogger [as 别名]
def urlParser(target):
log = logging.getLogger('urlparser')
ssl = False
o = urlparse(target)
if o[0] not in ['http', 'https', '']:
log.error('scheme %s not supported' % o[0])
return
if o[0] == 'https':
ssl = True
if len(o[2]) > 0:
path = o[2]
else:
path = '/'
tmp = o[1].split(':')
if len(tmp) > 1:
port = tmp[1]
else:
port = None
hostname = tmp[0]
query = o[4]
return (hostname, port, path, query, ssl)