本文整理汇总了Python中logger.logger.Logger.debug方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.debug方法的具体用法?Python Logger.debug怎么用?Python Logger.debug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logger.logger.Logger
的用法示例。
在下文中一共展示了Logger.debug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
def __init__(self, pdu_or_object):
self.pdu = {}
Logger.debug("PDU init (%s:%s)", (type(pdu_or_object), pdu_or_object), 'network_protocol')
if isinstance(pdu_or_object, dict):
Logger.trace("PDU init from dict", category='network_protocol')
self.from_dictionary(pdu_or_object)
else:
Logger.trace("PDU init from object", category='network_protocol')
self.from_object(pdu_or_object)
示例2: send_to_server_recursive_threaded_loop
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
def send_to_server_recursive_threaded_loop(connection_handler):
Logger.trace('loop from network process sender thread', category='client')
while not connection_handler.input_queue.empty():
payload = connection_handler.input_queue.get()
Logger.debug('fetch input_queue from network process sender thread', payload, category='client')
connection_handler.sendLine(json.dumps(payload))
time.sleep(0.01) # 10 ms
# get our Deferred which will be called with the largeFibonnaciNumber result
threads.deferToThread(send_to_server_recursive_threaded_loop, connection_handler)
示例3: forbid_root
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
def forbid_root(logger=None):
'''
Target:
- stop the execution of the program if this is being run by "root".
'''
if not logger:
logger = Logger()
try:
if getuser() == 'root': # Get system username
raise Exception()
except Exception as e:
logger.debug('Error en la función "forbid_root": {}.'.format(
str(e)))
logger.stop_exe(Messenger.ROOT_NOT_ALLOWED)
示例4: create_dir
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
def create_dir(path, logger=None):
'''
Target:
- stop the execution of the program if this is being run by "root".
Parameters:
- path: directory to create.
- logger: a logger to show and log some messages.
'''
if not logger:
logger = Logger()
try:
if not os.path.exists(path): # If path does not exist...
os.makedirs(path) # Create it
except Exception as e:
logger.debug('Error en la función "create_dir": {}.'.format(
str(e)))
logger.stop_exe(Messenger.USER_NOT_ALLOWED_TO_CHDIR)
示例5: db_filter_exclude
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
def db_filter_exclude(dbs_list, ex_dbs=[], ex_regex='', logger=None):
'''
Target:
- filter a list of databases to remove only the specified ones,
taking into account the received parameters.
Parameters:
- dbs_list: list to filter.
- ex_dbs: list with the databases' names to exclude.
- ex_regex: regular expression which indicates the databases' names
to exclude.
- logger: a logger to show and log some messages.
Return:
- a filtered list (subset of "dbs_list"), value from the addition
of the exclude conditions "ex_dbs" y "ex_regex".
'''
if not logger:
logger = Logger()
# Copy the list to remove remove positions without conflict errors
dbs_filtered = dbs_list[:]
if '*' in ex_dbs: # If exclude all...
return [] # Return an empty list
if ex_regex:
for db in dbs_list:
dbname = db['datname']
# If database's name is in the exclusion list or matches the
# regular expression...
if dbname in ex_dbs or re.match(ex_regex, dbname):
# Remove database from the list
dbs_filtered.remove(db)
logger.debug('Base de datos excluida: {}'.format(dbname))
else:
for db in dbs_list:
dbname = db['datname']
# If database's name is in the exclusion list...
if dbname in ex_dbs:
# Remove database from the list
dbs_filtered.remove(db)
logger.debug('Base de datos excluida: {}'.format(dbname))
return dbs_filtered
示例6: on_line_received
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
def on_line_received(self, json_payload):
Logger.debug('line received: %s', json_payload, 'server')
payload = json.loads(json_payload)
if payload and 'type' in payload and payload['type'] == 'user_input':
user_input = UserInputDataUnit(payload['content']).get_object()
self.game.apply_user_input_to_player(self.user_id, user_input)
self.update_game()
self.send_broadcast_payload_except_self({
'type': 'user_input',
'content': payload['content'],
'user': PlayerDataUnit(self.game.get_player(self.user_id)).get_pdu()
})
self.interval_executor.execute_if_interval_elapsed(self, lambda self: self.send_broadcast_payload(
{'type': 'game_state', 'content': GameDataUnit(self.game).get_pdu()}))
else:
Logger.error('Unknown message type: (%s)', json_payload, 'server_protocol')
示例7: db_filter_include
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
def db_filter_include(dbs_list, in_dbs=[], in_regex='', logger=None):
'''
Target:
- filter a list of databases to get only the specified ones, taking
into account the received parameters.
Parameters:
- dbs_list: list to filter.
- in_dbs: list with the databases' names to include.
- in_regex: regular expression which indicates the databases' names
to include.
- logger: a logger to show and log some messages.
Return:
- a filtered list (subset of "dbs_list"), value from the addition
of the include conditions "in_dbs" y "in_regex".
'''
if not logger:
logger = Logger()
dbs_filtered = []
if '*' in in_dbs: # If include all...
return dbs_list # Return the whole list
if in_regex:
for db in dbs_list:
dbname = db['datname']
# If database's name is in the inclusion list or matches the
# regular expression...
if dbname in in_dbs or re.match(in_regex, dbname):
dbs_filtered.append(db) # Add database to the list
logger.debug('Base de datos incluida: {}'.format(dbname))
else:
for db in dbs_list:
dbname = db['datname']
# If database's name is in the inclusion list...
if dbname in in_dbs:
dbs_filtered.append(db) # Add database to the list
logger.debug('Base de datos incluida: {}'.format(dbname))
return dbs_filtered
示例8: process
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
class Vacuumer:
in_dbs = [] # List of databases to be included in the process
in_regex = '' # Regular expression which must match the included databases
# Flag which determinates whether inclusion conditions predominate over the
# exclusion ones
in_priority = False
ex_dbs = [] # List of databases to be excluded in the process
ex_regex = '' # Regular expression which must match the excluded databases
# Flag which determinates whether the templates must be included
ex_templates = True
# Use other PostgreSQL user during the backup process (only for superusers)
db_owner = ''
# An object with connection parameters to connect to PostgreSQL
connecter = None
logger = None # Logger to show and log some messages
def __init__(self, connecter=None, in_dbs=[], in_regex='',
in_priority=False, ex_dbs=['postgres'], ex_regex='',
ex_templates=True, db_owner='', logger=None):
if logger:
self.logger = logger
else:
self.logger = Logger()
if connecter:
self.connecter = connecter
else:
self.logger.stop_exe(Messenger.NO_CONNECTION_PARAMS)
if isinstance(in_dbs, list):
self.in_dbs = in_dbs
else:
self.in_dbs = Casting.str_to_list(in_dbs)
if Checker.check_regex(in_regex):
self.in_regex = in_regex
else:
self.logger.stop_exe(Messenger.INVALID_IN_REGEX)
if isinstance(in_priority, bool):
self.in_priority = in_priority
elif Checker.str_is_bool(in_priority):
self.in_priority = Casting.str_to_bool(in_priority)
else:
self.logger.stop_exe(Messenger.INVALID_IN_PRIORITY)
if isinstance(ex_dbs, list):
self.ex_dbs = ex_dbs
else:
self.ex_dbs = Casting.str_to_list(ex_dbs)
if Checker.check_regex(ex_regex):
self.ex_regex = ex_regex
else:
self.logger.stop_exe(Messenger.INVALID_EX_REGEX)
if isinstance(ex_templates, bool):
self.ex_templates = ex_templates
elif Checker.str_is_bool(ex_templates):
self.ex_templates = Casting.str_to_bool(ex_templates)
else:
self.logger.stop_exe(Messenger.INVALID_EX_TEMPLATES)
if db_owner is None:
self.db_owner = Default.DB_OWNER
else:
self.db_owner = db_owner
message = Messenger.VACUUMER_VARS.format(
server=self.connecter.server, user=self.connecter.user,
port=self.connecter.port, in_dbs=self.in_dbs,
in_regex=self.in_regex, in_priority=self.in_priority,
ex_dbs=self.ex_dbs, ex_regex=self.ex_regex,
ex_templates=self.ex_templates, db_owner=self.db_owner)
self.logger.debug(Messenger.VACUUMER_VARS_INTRO)
self.logger.debug(message)
def vacuum_db(self, dbname):
'''
Target:
- vacuum a PostgreSQL database.
Parameters:
- dbname: name of the database which is going to be vacuumed.
Return:
- a boolean which indicates the success of the process.
'''
success = True
# Store the command to do
command = 'vacuumdb {} -U {} -h {} -p {}'.format(
dbname, self.connecter.user, self.connecter.server,
self.connecter.port)
try:
# Execute the command in console
result = subprocess.call(command, shell=True)
if result != 0:
raise Exception()
#.........这里部分代码省略.........
示例9: __init__
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
class KivaRunner:
"""
This class can run kiva with a certain set of parameters
and different temperture inputs.
"""
def __init__(self, working_dir, log_dir, compare_file, parameter_format, logger=None):
"""
parameter_format specifies what parameters from which files are needed.
[file, name, min, max, step]
"""
if logger == None:
self.log = Logger()
else:
self.log = logger
self.error = False
self.working_dir = working_dir
self.log_dir = log_dir
self.kiva_path = '../ext'
self.kiva_name = 'kiva_0D'
self.kiva_parameter_files = ['itape17', 'itape5', 'itapeERC', 'itapeRs']
self.parameter_format = parameter_format
self.log.debug("Parameter Format: %s" % self.parameter_format)
# this will later hold all kiva_parameter_files that
# need to be loaded as ITapeFile objects
self.itapes = {}
self.compare_file = compare_file
# Check if working directory exists and that it is empty
self.working_dir_indicator = os.path.join(self.working_dir, 'kivagen.working.dir')
if not os.path.isdir(self.working_dir):
self.log.error("'%s' does not exist." % self.working_dir)
self.error = True
self.working_dir = None
elif os.listdir(self.working_dir): # not empty
if not os.path.isfile(self.working_dir_indicator):
self.log.error("'%s' does not seem to be a working directory." % self.working_dir)
self.error = True
self.working_dir = None
return
else:
open(self.working_dir_indicator, 'a').close()
# Check that log dir exists
if not os.path.isdir(self.log_dir):
self.log.error("'%s' does not exist." % self.log_dir)
self.error = True
self.log_dir = None
# Check if input files exist
input_files = [self.compare_file]
input_files.append(os.path.join(self.kiva_path, self.kiva_name))
for parameter_file in self.kiva_parameter_files:
input_files.append(os.path.join(self.kiva_path, parameter_file))
for input_file in input_files:
if not os.path.isfile(input_file):
self.log.error("'%s' not found." % input_file)
self.error = True
# Parse compare file
self.compare_values = self._readCompareFile(self.compare_file)
# self.log.debug("self.compare_values = %s" % self.compare_values)
# Load Parameters
self._loadParameters()
# self.log.debug("self.param_list = %s" % self.param_list)
# --------------- Parameters --------------------------------------------------
def _loadParameters(self):
"""
Loads the start parameters from the itape files.
Also creates a lookup table to match parameter list index to
itape file and value id
"""
self.param_list = []
self.param_lookup = {}
# relaod parameters from file
for itape in self.itapes.values():
itape._open(itape.name)
param_index = 0
for param in self.parameter_format:
# if file has not been loaded before
if param[0] not in self.itapes:
f = os.path.join(self.kiva_path, param[0])
if param[0] in self.kiva_parameter_files:
if param[0] in ['itapeERC', 'itapeRs']:
self.itapes[param[0]] = ITapeFile(f, self.log)
else:
self.log.error("Failed to read %s. Can only read itapeERC and itapeRs." % f)
else:
self.log.error("Failed to read %s. Not in self.kiva_parameter_files (%s)" % self.kiva_parameter_files)
# try to get parameter id
ii = self.itapes[param[0]].getId(param[1])
if ii < 0:
self.log.error("Could not find '%s' in '%s'." % (param[1], param[0]))
self.param_list.append(None) # append None to get index right
else:
value = self.itapes[param[0]].getValue(ii)
self.param_list.append(self._checkParameter(value, param))
# remember itap file and value id
self.param_lookup[param_index] = [self.itapes[param[0]], ii]
param_index = param_index + 1
# now we should have collected all parameters
if len(self.param_list) != len(self.parameter_format):
sel.log.error("Only found %s elements. Expected %s!"
#.........这里部分代码省略.........
示例10: getFitness
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
time.sleep(0.5)
# Collect Results
self._collectIgnitionDelay()
return True
def getFitness(self):
"""
Call this after calling run.
This will return a fitness value based on the temperatures computed.
"""
score = 0.0
for value in self.results:
score += abs(value[0] - value[1])
return score
if __name__ == "__main__":
"""
Some test code
"""
import parameters
l = Logger()
l.setLogLevel('debug')
runner = KivaRunner('../work', '../log', '../ext/Detalierte Mechanismus.csv', parameters.parameter_format, l)
l.debug("Default Parameter Set: %s" % runner.getParameters())
runner.run(10)
l.debug("Fitness: %s" % runner.getFitness())
runner.setParameters([0.01])
l.debug("New Parameter Set: %s" % runner.getParameters())
runner.run(10)
l.debug("Fitness: %s" % runner.getFitness())
示例11: send_payload
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
def send_payload(self, payload):
payload = json.dumps(payload)
Logger.debug('send payload to self only: %s', payload, 'server')
self.sendLine(payload)
示例12: file
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
class RestorerCluster:
# An object with connection parameters to connect to PostgreSQL
connecter = None
logger = None # Logger to show and log some messages
cluster_backup = '' # Absolute path of the backup file (of a cluster)
def __init__(self, connecter=None, cluster_backup='', logger=None):
if logger:
self.logger = logger
else:
self.logger = Logger()
if connecter:
self.connecter = connecter
else:
self.logger.stop_exe(Messenger.NO_CONNECTION_PARAMS)
if cluster_backup and os.path.isfile(cluster_backup):
self.cluster_backup = cluster_backup
else:
self.logger.stop_exe(Messenger.NO_BKP_TO_RESTORE)
message = Messenger.CL_RESTORER_VARS.format(
server=self.connecter.server, user=self.connecter.user,
port=self.connecter.port, cluster_backup=self.cluster_backup)
self.logger.debug(Messenger.CL_RESTORER_VARS_INTRO)
self.logger.debug(message)
def restore_cluster_backup(self):
'''
Target:
- restore a cluster's backup in PostgreSQL. The cluster must have
been created before this process.
'''
# Regular expression which must match the backup's name
regex = r'.*ht_(.+_cluster)_(\d{8}_\d{6}_.+)\.(dump|bz2|gz|zip)$'
regex = re.compile(regex)
if re.match(regex, self.cluster_backup):
# Store the parts of the backup's name (servername, date, ext)
parts = regex.search(self.cluster_backup).groups()
# Store only the extension to know the type of file
ext = parts[2]
else:
Messenger.NO_BACKUP_FORMAT
message = Messenger.BEGINNING_CL_RESTORER.format(
cluster_backup=self.cluster_backup)
self.logger.highlight('info', message, 'white')
self.logger.info(Messenger.WAIT_PLEASE)
# TODO: make dissappear every line about the operation shown in console
if ext == 'gz':
command = 'gunzip -c {} -k | psql postgres -U {} -h {} ' \
'-p {}'.format(
self.cluster_backup, self.connecter.user,
self.connecter.server, self.connecter.port)
elif ext == 'bz2':
command = 'bunzip2 -c {} -k | psql postgres -U {} -h {} ' \
'-p {}'.format(
self.cluster_backup, self.connecter.user,
self.connecter.server, self.connecter.port)
elif ext == 'zip':
command = 'unzip -p {} | psql postgres -U {} -h {} -p {}'.format(
self.cluster_backup, self.connecter.user,
self.connecter.server, self.connecter.port)
else:
command = 'psql postgres -U {} -h {} -p {} < {}'.format(
self.connecter.user, self.connecter.server,
self.connecter.port, self.cluster_backup)
try:
start_time = DateTools.get_current_datetime()
# Make the restauration of the cluster
result = subprocess.call(command, shell=True)
end_time = DateTools.get_current_datetime()
# Get and show the process' duration
diff = DateTools.get_diff_datetimes(start_time, end_time)
if result != 0:
raise Exception()
message = Messenger.RESTORE_CL_DONE.format(
cluster_backup=self.cluster_backup, diff=diff)
self.logger.highlight('info', message, 'green')
self.logger.highlight('info', Messenger.RESTORER_DONE, 'green',
effect='bold')
except Exception as e:
self.logger.debug('Error en la función "restore_cluster_backup": '
'{}.'.format(str(e)))
message = Messenger.RESTORE_CL_FAIL.format(
cluster_backup=self.cluster_backup)
self.logger.stop_exe(message)
示例13: stop
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
def stop(self):
Logger.debug('stop command received from network process', category='client')
self.input_queue.put('quit')
multiprocessing.Process.terminate(self)
示例14: run
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
def run(self):
Logger.debug('process start from network process', category='client')
reactor.connectTCP('127.0.0.1', 5000, ClientFactory(self.input_queue, self.output_queue))
reactor.run()
示例15: version
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import debug [as 别名]
class Connecter:
'''This class manages connections with database engines and operations
involving them.
So far, only PostgreSQL is supported.
'''
conn = None # The PostgreSQL connection object
cursor = None # The cursor of the PostgreSQL connection
server = None # The target host of the connection
user = None # The PostgreSQL user who makes the connection
port = None # The target port of the connection
database = None # The target database of the connection
logger = None # A logger to show and log some messages
# PostgreSQL version (from this one on some variables change their names)
PG_PID_VERSION_THRESHOLD = 90200
pg_pid_91 = 'procpid' # Name for PostgreSQL PID variable till version 9.1
pg_pid_92 = 'pid' # Name for PostgreSQL PID variable since version 9.2
def __init__(self, server, user, port, database=None, logger=None):
if logger:
self.logger = logger
else:
self.logger = Logger()
self.server = server
self.user = user
if isinstance(port, int):
self.port = port
elif Checker.str_is_int(port):
self.port = Casting.str_to_int(port)
else:
self.logger.stop_exe(Msg.INVALID_PORT)
if database is None:
self.database = Default.CONNECTION_DATABASE
elif database:
self.database = database
else:
self.logger.stop_exe(Msg.NO_CONNECTION_DATABASE)
try:
self.conn = psycopg2.connect(host=self.server, user=self.user,
port=self.port,
database=self.database)
self.conn.autocommit = True
# TODO: ask for a password here if possible
self.cursor = self.conn.cursor(
cursor_factory=psycopg2.extras.DictCursor)
except Exception as e:
self.logger.debug('Error en la función "pg_connect": {}.'.format(
str(e)))
self.logger.stop_exe(Msg.CONNECT_FAIL)
def pg_disconnect(self):
'''
Target:
- disconnect from PostgreSQL.
'''
try:
self.cursor.close()
self.conn.close()
except Exception as e:
self.logger.debug('Error en la función "pg_disconnect": '
'{}.'.format(str(e)))
self.logger.stop_exe(Msg.DISCONNECT_FAIL)
def get_pg_version(self):
'''
Target:
- get the PostgreSQL version.
Return:
- a integer which gives the PostgreSQL version.
'''
return self.conn.server_version
def get_pretty_pg_version(self):
'''
Target:
- get the pretty PostgreSQL version.
Return:
- a string which gives the PostgreSQL version and more details.
'''
try:
self.cursor.execute(Queries.GET_PG_PRETTY_VERSION)
pretty_pg_version = self.cursor.fetchone()
return pretty_pg_version[0]
except Exception as e:
# Rollback to avoid errors in next queries because of waiting
# this transaction to finish
self.conn.rollback()
self.logger.debug('Error en la función "get_pretty_pg_version": '
'{}.'.format(str(e)))
self.logger.highlight('warning', Msg.GET_PG_VERSION_FAIL, 'yellow')
return None
#.........这里部分代码省略.........