本文整理汇总了Python中utils.Logger类的典型用法代码示例。如果您正苦于以下问题:Python Logger类的具体用法?Python Logger怎么用?Python Logger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getKillCmd
def _getKillCmd(self):
if self._shouldUseCmdList():
killCmd = self._killCmdPath()
Logger.log("Kill cmd path:%s" % killCmd, Logger.LOG_DEBUG)
return [killCmd, '-SIGINT' , 'openvpn']
else:
return 'killall -SIGINT openvpn'
示例2: _writeOpenVPNConfiguration
def _writeOpenVPNConfiguration(self, authPath):
openVpnConfigFilePath = config.getOpenVPNTemplateConfigFilePath()
cert = config.getCertFilePath()
file = open(openVpnConfigFilePath, mode='r')
content = file.read()
file.close()
authPath = authPath.replace('\\', '/')
cert = cert.replace('\\', '/')
content = content.replace('#SERVER#', self._serverAddress)
content = content.replace('#PORT#', self._port)
content = content.replace('#CERTIFICATE#', '"' + cert + '"')
content = content.replace('#AUTHENTICATION#', '"' + authPath + '"')
# Adding the log will disable the output to be written to stdout, so Windows will fail reading the status
# so in case it is needed this should be added on the modifyOpenVPNConfigContent for the correspondent OS
#content += "\r\nlog " + "openvpn1.log"
# The goal is to modify the OpenVPN Config for adding config options that may be needed for some OSs (like Linux Ubuntu)
content = self._modifyOpenVPNConfigContent(content)
Logger.log("OpenVPN configuration:%r" % content)
cfgFilePath = self._getOpenVPNConfigPath()
file = open(cfgFilePath, mode='w+')
file.write(content)
file.close()
return cfgFilePath
示例3: handle_receive
def handle_receive(self, packet, time):
if isinstance(packet, AckPacket):
Rn = packet.request_number
self.last_n_req_nums.append(Rn)
if len(self.last_n_req_nums) > TCPReno.MAX_DUPLICATES:
self.last_n_req_nums.pop(0)
Sn, Sb, Sm = self.host.sequence_nums
cwnd = self.host.cwnd
if self.last_drop is None or \
time - self.last_drop > TCPReno.TIMEOUT_TOLERANCE:
if len(self.last_n_req_nums) == TCPReno.MAX_DUPLICATES and \
all(num == Rn for num in self.last_n_req_nums):
# If we've had duplicate ACKs, then enter fast retransmit.
self.ssthresh = max(self.host.cwnd / 2, TCPReno.INITIAL_CWND)
self.set_window_size(time, self.ssthresh)
Logger.warning(time, "Duplicate ACKs received for flow %s." % self.host.flow[0])
self.last_drop = time
if self.ss:
self.set_window_size(time, cwnd + 1)
if self.host.cwnd >= self.ssthresh:
self.ss = False
Logger.info(time, "SS phase over for Flow %s. CA started." % (self.host.flow[0]))
elif Rn > Sb:
# If we are in Congestion Avoidance mode, we wait for an RTT to
# increase the window size, rather than doing it on ACK.
self.set_window_size(time, cwnd + 1. / cwnd)
示例4: sensing_decision
def sensing_decision(self, sensing_result, number_cpes):
"""
Algorithm sensing decision.
@param sensing_result
@param number_cpes
"""
#print "simple cycle"
#feedback cycle control
self._fb_cycle += 1
#initialize sum of scores for each decision (0,1)
sum_result0 = 0.0
sum_result1 = 0.0
#keeps the greatest reward for each decision
greatest_reward0 = 0.0
greatest_reward1 = 0.0
#sum of all scores for each decision
for decision, reward in zip(sensing_result, self._reward):
#sum of scores for "0" decision
if decision == IDLE:
sum_result0 += reward
if reward > greatest_reward0:
greatest_reward0 = reward
#sum of scores for "1" decision
elif decision == OCCUPIED:
sum_result1 += reward
if reward > greatest_reward1:
greatest_reward1 = reward
#divide the sum of scores by the total number of CPEs
score_r1 = sum_result1 / number_cpes
score_r0 = sum_result0 / number_cpes
#verifies which sum of scores is higher, score1 or score0
if score_r0 > score_r1:
sensing_decision = IDLE
elif score_r0 < score_r1:
sensing_decision = OCCUPIED
#if both scores are equal, then verifies the decision made by the cpe with the greatest individual score
elif score_r0 == score_r1:
if greatest_reward0 >= greatest_reward1:
sensing_decision = IDLE
elif greatest_reward0 < greatest_reward1:
sensing_decision = OCCUPIED
#verifies if is feedback cycle
#if (self._fb_cycle % (feedback_control-1) == 0):
Logger.append('sdc', 'decision', sensing_decision)
if sensing_decision == OCCUPIED:
self._total_occ += 1
else:
self._total_idle += 1
self.feedback(sensing_result, sensing_decision, increase_rate, decrease_rate)
示例5: timeout
def timeout(self, time, packet):
"""
A timeout occurred at the given time on the given packet. Resend if
necessary.
:param time: Time to resend the packet
:type time: int
:param packet: Packet which timed out
:type packet: Packet
"""
# We already received an Ack for it
if packet.id not in self.awaiting_ack:
return
else:
# Otherwise, remove it so that it will be added again
del self.awaiting_ack[packet.id]
if not isinstance(packet, FlowPacket):
# If an ACK packet is dropped, don't worry about it, it'll be sent
# again later
return
flow_id = packet.flow_id
if self.current_request_num is not None and \
packet.sequence_number < self.current_request_num:
# Packet was already received
return
self.congestion_control.handle_timeout(packet, time)
# Resend
Logger.info(time, "Packet %s was dropped, resending" % (packet.id))
self.queue.add(packet)
self.send_packets(time, flow_id)
示例6: _allowAction
def _allowAction(self, action, extra = ''):
Logger.log("allowAction %s" % action, Logger.LOG_DEBUG)
user = self._getUsername()
pwd = config.getPassword()
data = {"username" : user, "apiKey" : pwd, "action" : action, "country" : self._countryName, "city" : self._cityName, "server" : self._serverAddress, "extra" : extra, "os" : config.getOS()}
self._actionNotification.push(data)
示例7: _Job
class _Job(object):
def __init__(self):
self.log = Logger(self.__class__.__name__, fh)
self.log.debug("Job is created")
def execute(self, **kwargs):
try:
self.log.debug("Start job with kwargs=%s" % kwargs)
self._execute(**kwargs)
self.log.debug("Finish job successful")
except Exception as e:
self.log.exception("Error during job execution")
subject = 'Tasker Information. Произошла ошибка в скрипте %s' % self.__class__.__name__
self.log.debug(subject)
# send_email(subject, as_text(e.message),
# send_from=SMTP_SETTINGS['username'],
# server=SMTP_SETTINGS['server'],
# port=SMTP_SETTINGS['port'],
# user=SMTP_SETTINGS['username'],
# passwd=SMTP_SETTINGS['password'],
# dest_to=ERROR_EMAILS)
def _execute(self, **kwargs):
raise NotImplementedError("%s._execute" % self.__class__.__name__)
@classmethod
def run(cls, **kwargs):
log.debug("in _Job.run!")
return cls().execute(**kwargs)
示例8: decision
def decision(self, energy):
"""
@param energy
"""
energy = np.sum(energy) / energy.size
self.cycle_counter += 1
if self.cycle_counter_max == self.cycle_counter:
self.cycle_counter = 0
sp = self.do_action(self.s, self.a)
rw = self.get_reward(energy, sp)
ap = self.e_greedy_selection(sp)
self.update_q_table(self.s, self.a, rw, sp, ap)
self.s = sp
self.a = ap
#self.epsilon *= 0.999
Logger.append('bayes_learning', 'hypothesis', 1.0 if energy > self.s else 0.0)
Logger.append('bayes_learning', 'feedback', self._feedback)
Logger.append('bayes_learning', 'state', self.s)
Logger.append('bayes_learning', 'reward', rw)
Logger.append('bayes_learning', 'action', self.a)
return 1 if (energy > sp) else 0, energy
示例9: __init__
def __init__(self, in_th, min_th, max_th, delta_th, k):
"""
CTOR
@param in_th Initial threshold.
@param min_th Minimum threshold.
@param max_th Maximum threshold.
@param k Bayesian k factor.
"""
Logger.register('bayes_decision', ['threshold', 'decision', 'risk'])
self._feedback = self._feedback_prev = -1
self._delta_th = delta_th
self._min_th_limit = min_th
self._max_th_limit = max_th
self._k = k
self._th = in_th
self.init(in_th)
self._th_dec = {}
self._xx = {};
self._xx[0] = {0: "00", 1: "01"}
self._xx[1] = {0: "10", 1: "11"}
示例10: main
def main(env_name, num_episodes, render, VideoSave, gamma, lam, kl_targ, batch_size):
killer = GracefulKiller()
env, obs_dim, act_dim = init_gym(env_name, render)
obs_dim += 1 # add 1 to obs dimension for time step feature (see run_episode())
now = datetime.utcnow().strftime("%b-%d_%H-%M-%S") # create unique directories
logger = Logger(logname=env_name, now=now)
#aigym_path = os.path.join('/tmp', env_name, now)
#env = wrappers.Monitor(env, aigym_path, force=True)
scaler = Scaler(obs_dim, env_name)
scaler.resume()
val_func = NNValueFunction(obs_dim, env_name)
policy = Policy(obs_dim, act_dim, kl_targ, env_name)
episode = 0
capture = False
while episode < num_episodes:
if VideoSave and not capture:
env.ScreenCapture(5)
capture = True
trajectories = run_policy(env, policy, scaler, logger, episodes=batch_size)
episode += len(trajectories)
if killer.kill_now:
if input('Terminate training (y/[n])? ') == 'y':
break
killer.kill_now = False
logger.close()
policy.close_sess()
val_func.close_sess()
示例11: _getItems
def _getItems(self):
try:
html = GetContentFromUrl(self.URL)
return re.compile(self.REGEX).findall(html)
except urllib2.URLError, e:
Logger.log("There was an error while getting content from remote server")
raise NoConnectionError("There was an error while getting content from remote server")
示例12: add_print_list
def add_print_list():
"""
Adds to the print list (method of the Logger class)
"""
print "\n******************************************************************\n"
print "\nPrinting the energy\n"
Logger.add_to_print_list("energy_decision", "energy")
print "\n******************************************************************\n"
示例13: _connectAndCheckStatus
def _connectAndCheckStatus(self, busy = None):
# Erase the Remote Controller status file because if not the Controller appends into that file
self._eraseRemoteControllerStatusFile()
Logger.log("Android _doConnect starting ...", Logger.LOG_DEBUG)
ret = self._runRemoteController(self.OPENVPN_CONNECT_ACTION, self._timeout)
if not ret:
gui.DialogOK(__language__(30017), __language__(30018), "")
return
statusDone = False
startTime = time.time()
elapsed = 0
MAX_TIMEOUT = 60
statusGrabbed = False
status = ''
while elapsed < MAX_TIMEOUT:
status = self._getCurrentStatus()
Logger.log("Checking Status:%s" % status, Logger.LOG_DEBUG)
ASSIGN_IP = 'ASSIGN_IP;'
# Check if after the ASSIGN_IP notification a CONNECTED; SUCCESS is notified
if ASSIGN_IP in status and 'CONNECTED; SUCCESS' in status[status.find(ASSIGN_IP):]:
Logger.log("VPN IP assigned and connected Ok", Logger.LOG_INFO)
msg1, msg2, msg3 = self._connectionOkMessage()
gui.DialogOK(msg1, msg2, msg3)
statusGrabbed = True
break
elif 'USER_DID_NOT_APPROVE_THE_APP' in status:
gui.DialogOK(__language__(30019), __language__(30005), "")
statusGrabbed = True
break
elif 'EXITING; auth-failure' in status:
gui.DialogOK(__language__(30038), __language__(30037), __language__(30005))
self.kill()
statusGrabbed = True
break
xbmc.sleep(1000)
elapsed = time.time() - startTime
Logger.log("_GetCurrent status:::")
print status
if not statusGrabbed:
gui.DialogOK(__language__(30020), __language__(30021), __language__(30005))
Logger.log("ERROR it break the loop with timeout. Check the notification status", Logger.LOG_ERROR)
if busy:
busy.close()
return statusGrabbed
示例14: work
def work(self, input_items, output_items):
for idx in range(len(input_items[0])):
decf, vf = self.algo1.decision(input_items[0][idx])
if decf == 0:
decf, vf = self.algo2.decision(input_items[1][idx])
Logger.append('hier', 'decision', self._xx[Logger._ch_status][decf])
return len(input_items[0])
示例15: execute
def execute(paramsDictionary, message):
logger.logInfo(NAME + "wewnatrz modulu rozglaszania nowej wersji ")
homePath = paramsDictionary["HOME_PATH"]
lock = paramsDictionary["LOCK"]
if lock.is_locked == False:
return
try:
addressesfile = FileProcessor(paramsDictionary["HOME_PATH"]+"ServerSide/config/addresses.conf")
addressesfile.lockFile()
addresses = addressesfile.readFile()
addressesfile.unlockFile()
versionsFile = FileProcessor(homePath+"ServerSide/config/database_config/data_version.dat")
versionsFile.lockFile()
dataVersions = versionsFile.readFile()
versionsFile.unlockFile()
myVersion = dataVersions[LOCALHOST_NAME]
logger.logInfo(NAME + "Moja wersja danych " + myVersion)
for address in addresses:
if addresses[address] == "T":
logger.logInfo(NAME + "wysylanie wersji do " + address)
connection = Connection(homePath + "ServerSide/config/connection_config.conf" )
if connection.connect(address, 80, RESOURCE) == OK_FLAG:
connection.send_message(myVersion)
connection._do_closing_handshake()
else:
logger.logError(NAME + "Nie moge polaczyc sie z serwerem o adresie " + address)
except Exception, e:
logger.logError(NAME + e.message)
lock.release