本文整理汇总了Python中logger.logger.Logger.log方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.log方法的具体用法?Python Logger.log怎么用?Python Logger.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logger.logger.Logger
的用法示例。
在下文中一共展示了Logger.log方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BinaryKnob
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import log [as 别名]
class BinaryKnob(object):
value = 0
pins = []
logger = None
def __init__(self, pins):
self.logger = Logger()
self.pins = pins
add_event_detection(self.pins[0], self.__handle_change, True)
add_event_detection(self.pins[1], self.__handle_change, True)
add_event_detection(self.pins[2], self.__handle_change, True)
self.__handle_change
def get_value(self):
self.__handle_change(1)
return self.value
def __handle_change(self, pin):
a = GPIO.input(self.pins[0])
b = GPIO.input(self.pins[1])
c = GPIO.input(self.pins[2])
self.value = 1
if a == True:
self.value += 1
if b == True:
self.value += 2
if c == True:
self.value += 4
self.logger.log("Selected %s" % self.value)
示例2: Button
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import log [as 别名]
class Button(object):
value = 0
pin = None
logger = None
def __init__(self, pin, callback):
self.logger = Logger()
self.pin = pin
if callback is None:
add_event_detection(self.pin, self.__default_callback, True)
else:
add_event_detection(self.pin, callback, True)
self.__handle_change
def __default_callback(self):
self.logger.log("Button: at pin %s callback with default callback")
def get_value(self):
self.__handle_change(1)
return self.value
示例3: Printer
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import log [as 别名]
class Printer(object):
conn = cups.Connection()
printers = conn.getPrinters()
printer_name = printers.keys()[0]
tmpfilePath = "/home/pi/tmpadventure.pdf"
ready_to_print = True
logger = None
def __init__(self):
self.logger = Logger()
def __print(self):
self.logger.log("Printer: printing using %s" % self.printer_name)
self.conn.cancelAllJobs(self.printer_name)
self.conn.printFile(self.printer_name, self.tmpfilePath, "adventure", {})
def __create_file(self, adventure):
self.logger.log("Printer: creating pdf")
try:
os.remove(self.tmpfilePath)
self.logger.log(" Success")
except OSError:
self.logger.log(" Failure")
pass
title = adventure["title"].replace("\\n", "\n")
desc = adventure["desc"].replace("\\n", "\n")
pdf = Adventure()
pdf.set_margins(left=18, top=0, right=0)
pdf.set_auto_page_break(False)
pdf.add_page(orientation='P', format=(90,115))
pdf.set_font('Arial', 'B', 16)
pdf.multi_cell(0, 6, title, align='C')
pdf.ln()
pdf.set_font('Arial', '', 12)
pdf.multi_cell(0, 6, desc, align='C')
pdf.output(self.tmpfilePath, 'F')
def __ready_to_print(self):
self.logger.log("Printer: setting ready to print from %s to True" % self.ready_to_print)
self.ready_to_print = True
def printAdventure(self, adventure):
self.logger.log("Printer: trying to print adventure with id %s and ready status %s" % (adventure['id'], self.ready_to_print))
if self.ready_to_print:
self.__create_file(adventure)
self.__print()
self.ready_to_print = False
t = threading.Timer(1.0, self.__ready_to_print)
t.start()
示例4: CoinMachine
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import log [as 别名]
class CoinMachine(object):
coin_input_pin = 21
coin_counter_input_pin = 12
coin_counter_pins = [29, 31]
lighting = None
waiting_for_coin = False
accepted_a_coin = False
coin_detected = False
coin_counted = False
coin_pending = False
demo_mode = False
current_value = 0
logger = None
def __init__(self, lighting, demo_mode=False):
self.logger = Logger()
self.demo_mode = demo_mode
self.lighting = lighting
GPIO.setup(self.coin_counter_pins, GPIO.OUT)
GPIO.setup(self.coin_input_pin, GPIO.IN)
GPIO.setup(self.coin_counter_input_pin, GPIO.IN)
self.__set_coin_count(0)
self.start_waiting_for_coin()
# Public --------------------------------------------
def start_waiting_for_coin(self):
self.logger.log("Coin: waiting for coin at pin %s" % self.coin_input_pin)
add_event_detection(self.coin_input_pin, callback=self.__coin_cb)
add_event_detection(self.coin_counter_input_pin, callback=self.__coin_counter_cb)
self.waiting_for_coin = True
def clear_coins(self):
self.logger.log("Coin: clearing count")
self.__set_coin_count(0)
def subtract_coins(self, num):
self.logger.log("Coin: new coin count = %s - %s" % (self.current_value, num))
self.__set_coin_count(self.current_value - num)
# Private -------------------------------------------
def __coin_cb(self, channel):
self.logger.log("Coin: coin cb with waiting status: %s" % self.waiting_for_coin)
if self.waiting_for_coin is True:
self.__coin_detected()
self.coin_detected = True
def __coin_counter_cb(self, channel):
self.logger.log("Coin: coin counter cb with waiting status: %s" % self.waiting_for_coin)
if self.waiting_for_coin is True:
self.__coin_detected()
self.coin_counted = True
def __coin_detected(self):
self.logger.log("Coin: coin detected with pending status: %s" % self.coin_pending)
if self.coin_pending is False:
self.coin_pending = True
self.coin_detected = False
self.coin_counted = False
t = threading.Timer(1.0, self.__done_waiting_for_coin)
t.start()
def __done_waiting_for_coin(self):
self.logger.log("Coin: done waiting with pending status")
self.coin_detected = True
#Fake the coin detection for now, it's broken
if self.coin_detected is True and self.coin_counted is True:
self.logger.log(" Got a coin, pick a box")
self.__set_accepted_coin(True)
else:
self.logger.log(" Not accepted")
self.coin_detected = False
self.coin_counted = False
self.coin_pending = False
def __wait_for_coin(self):
self.logger.log("Coin: waiting_for_coin set to true, was: %s" % self.waiting_for_coin)
self.waiting_for_coin = True
def __set_accepted_coin(self, value):
self.logger.log("Coin: accepting coin with value %s" % value)
self.accepted_a_coin = value
if value is True:
self.lighting.coin_received()
try:
if self.demo_mode is True:
#If it's demo mode, then we should only allow 1 credit
self.__set_coin_count(1)
else:
self.__set_coin_count(self.current_value + 1)
except RuntimeError:
self.logger.log(" error set_accepted_coin")
#.........这里部分代码省略.........
示例5: VendingMachine
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import log [as 别名]
class VendingMachine(object):
adventure_button_pin = 18
gift_button_pin = 16
adventure_type_pin = 22
box_select_pins_a = [24,26,32]
box_select_pins_b = [36,38,40]
out_of_service_pin = 23
price_pins = [33,35,37]
#Change this to False to use in the real vending machine
#Leave as True to use the demo box with three buttons
demo_mode = False
random_box_mode = False
print_adventures = True
box_controller = None
printer = None
#deprecated by ligting system
lighting = None
server = None
adventure_knob_a = None
adventure_knob_b = None
coin_machine = None
logger = None
api = None
adventure_count = 0
gift_count = 0
adv_types = [["bmapi", 40], ["fun", 10], ["coin", 60]]
def __init__(self):
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
self.logger = Logger()
self.__init_pins()
self.box_controller = BinaryBoxController()
self.printer = Printer()
LightSystemManager.setup()
#depracted by lighting system manager
self.lighting = LightingController()
self.adventure_knob_a = BinaryKnob(self.box_select_pins_a)
self.adventure_knob_b = BinaryKnob(self.box_select_pins_b)
self.coin_machine = CoinMachine(self.lighting, self.demo_mode)
self.server = api.run.ServerController()
self.api = api.run
# Private -------------------------------------------
def __init_pins(self):
self.logger.log("Machine: initializing pins")
GPIO.setup(self.out_of_service_pin, GPIO.OUT)
GPIO.setup(self.price_pins, GPIO.OUT)
GPIO.setup(self.adventure_type_pin, GPIO.IN)
GPIO.output(self.out_of_service_pin, True)
GPIO.output(self.price_pins[0], True)
GPIO.output(self.price_pins[1], True)
GPIO.output(self.price_pins[2], True)
def __adventure_button_cb(self, pin):
self.logger.log("Machine: adventure button pressed with waiting status: %s" % self.waiting_to_give_adventure)
if self.waiting_to_give_adventure == True:
self.logger.log(" Dispensing Adventure")
self.dispense_adventure()
self.waiting_to_give_adventure = False
t = threading.Timer(1.0, self.__allow_dispensing_adventures)
t.start()
def __allow_dispensing_adventures(self):
self.waiting_to_give_adventure = True
def __start_waiting_for_user(self):
self.logger.log("Machine: waiting for user at pin %s" % self.adventure_button_pin)
add_event_detection(self.adventure_button_pin, callback=self.__adventure_button_cb)
add_event_detection(self.gift_button_pin, callback=self.__gift_button_pressed)
self.__allow_dispensing_adventures()
def __reset_box(self):
self.box_controller.close_boxes()
def __start_waiting_for_boxes(self):
self.logger.log("Machine: waiting for boxes with demo mode: %s" % self.demo_mode)
if self.demo_mode == True:
add_event_detection(self.box_select_pins_a[0], callback=self.__box_a_pressed)
add_event_detection(self.box_select_pins_a[1], callback=self.__box_b_pressed)
add_event_detection(self.box_select_pins_a[2], callback=self.__box_c_pressed)
def __box_a_pressed(self, channel):
self.logger.log("Machine: box button a pressed")
self.open_prize_box(1)
self.lighting.box_selected(1)
def __box_b_pressed(self, channel):
self.logger.log("Machine: box button b pressed")
self.open_prize_box(2)
self.lighting.box_selected(2)
def __box_c_pressed(self, channel):
self.logger.log("Machine: box button b pressed")
#.........这里部分代码省略.........
示例6: BinaryBoxController
# 需要导入模块: from logger.logger import Logger [as 别名]
# 或者: from logger.logger.Logger import log [as 别名]
class BinaryBoxController(object):
binary_output_pins = [3,5,7,11]
mux_enable_output_pins = [13,15]
current_binary_output = [0,0,0,0]
lower_mux_disabled = 1
higher_mux_disabled = 1
currently_open = False
logger = None
def __init__(self):
GPIO.setup(self.binary_output_pins, GPIO.OUT)
GPIO.setup(self.mux_enable_output_pins, GPIO.OUT)
self.logger = Logger()
self.__set_latch(self.binary_output_pins[0], 0)
self.__set_latch(self.binary_output_pins[1], 0)
self.__set_latch(self.binary_output_pins[2], 0)
self.__set_latch(self.binary_output_pins[3], 0)
self.close_boxes()
def set_box(self, number):
#Change the number to counting at 0 instead of 1
number = number - 1
binary_num = '{0:05b}'.format(number);
if binary_num[0] == '1':
self.higher_mux_disabled = 0
self.lower_mux_disabled = 1
else:
self.higher_mux_disabled = 1
self.lower_mux_disabled = 0
self.current_binary_output = [
int(binary_num[4]),
int(binary_num[3]),
int(binary_num[2]),
int(binary_num[1])]
def open_current_box(self):
if self.currently_open:
self.close_boxes()
#Set the box number
self.__set_latch(self.binary_output_pins[0], self.current_binary_output[0])
self.__set_latch(self.binary_output_pins[1], self.current_binary_output[1])
self.__set_latch(self.binary_output_pins[2], self.current_binary_output[2])
self.__set_latch(self.binary_output_pins[3], self.current_binary_output[3])
#Enable the muxes
self.__set_latch(self.mux_enable_output_pins[0], self.lower_mux_disabled)
self.__set_latch(self.mux_enable_output_pins[1], self.higher_mux_disabled)
def close_boxes(self):
self.__set_latch(self.mux_enable_output_pins[0], 1)
self.__set_latch(self.mux_enable_output_pins[1], 1)
def __set_latch(self, pin, value):
self.logger.log("Setting Latch %s to %s" % (pin, value))
try:
GPIO.output(pin, value)
except RuntimeError:
self.logger.log("Error setting Latch")