예제 #1
0
def run_test():
    import time
    import logging
    from src.util.logger import Logger
    start = time.time()
    logger = Logger(flush_internal=3, buffer_len_bound=20480)
    i = 0
    while i < 100000:
        logger.error("hello world {}".format(i))
        i += 1
    delta = time.time() - start
    print delta

    # 对比,效率主要区别在文件打开次数上
    start = time.time()
    logger_name = 'simple_logger'
    logger = logging.getLogger(logger_name)
    logger.setLevel(logging.DEBUG)
    file_handler = logging.FileHandler('test.log')
    file_handler.setFormatter(
        logging.Formatter(
            "%(asctime)s	%(thread)d	%(levelname)s	%(pathname)s:%(lineno)d	%(message)s"
        ))
    logger.addHandler(file_handler)
    i = 0
    while i < 100000:
        logger.error("hello world {}".format(i))
        i += 1

    delta = time.time() - start
    print delta

    # TEST version 2.0
    Logger.start_logger_service()
    LOG.error("TEST")
예제 #2
0
 def __init__(self):
     self.LOGGER = Logger(self)
     self.controller = Adafruit_MotorHAT(addr=0x60, i2c_bus=1)
     self.motors = [0, 0, 0, 0]
     # Initialize motor subscribers
     rospy.init_node('interface')
     rospy.Subscriber("/motor", String, self.on_motor_callback, queue_size=1)
     # Turn off motors when the script exits.
     atexit.register(self.turn_off_motors)
     # Motor tracking
     r = rospy.Rate(2)
     while not rospy.is_shutdown():
         self.LOGGER.info(str(self.motors))
         r.sleep()
예제 #3
0
class Driver:
    '''
    Driver class contains method and initialization of commandline arguments
    '''
    # command line argument initialization
    parser = argparse.ArgumentParser()
    parser.add_argument('--file',
                        '--f',
                        default="../input/input.txt",
                        help='Input file path')
    parser.add_argument("--topxltv",
                        default=2,
                        help='Finds top x ltv valued customers')
    parser.add_argument('--loglevel',
                        default='INFO',
                        help='Level of logging to use (default:WARNING, \
                        values: CRITICAL, ERROR, WARNING, INFO, DEBUG)')
    parser.add_argument('--output',
                        default='../output/output.txt',
                        help='Output File path')
    args = parser.parse_args()

    if __name__ == '__main__':
        # Instatiation of logger object
        logObj = Logger()
        log = logObj.logger(args.loglevel)
        # Instatiation of FileProcessor object
        file_process = FileProcessor(log)
        log.info("File Processed")
        # Reads the data from input file
        data = file_process.read_file(args.file)
        # Instatiation of EventMapper object
        event = event_mapper.EventMapper(log)
        # Instatiation of Data D from DataStore
        D = DataStore()

        for e in data:
            # Feeding event one by one to Ingest method
            event.Ingest(e, D)
        # Call for calculating top x customer based on LTV value
        if int(args.topxltv) > 0:
            x = int(args.topxltv)
        else:
            x = 2
        write_data = event.TopXSimpleLTVCustomers(x, D)
        # Write top x customers to the output file
        file_process.write_file(args.output, write_data)
from os import environ
from os.path import join, dirname
from dotenv import load_dotenv

sys.path.append(join(dirname(__file__), '../..'))
from src.util.logger import Logger


# Load Slack API Token
load_dotenv(join(join(dirname(__file__), '../..'), '.env'))
TOKEN = environ.get("SLACK_API_TOKEN")

# Create Slack client
client = slack.WebClient(token=TOKEN)

LOGGER = Logger()


def get_ip_address():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))
    return s.getsockname()[0]

def notify_ip():
    """
    Notifies the Slack channel of the car's IP address.
    """
    ip = get_ip_address()
    LOGGER.info("IP: " + ip)
    LOGGER.info("Token: " + TOKEN)
    response = client.chat_postMessage(channel='#autonomy-bot', text="Hi! SSH into me with `ssh pi@" + ip + "`.")
예제 #5
0
 def __init__(self):
     self.LOGGER = Logger(self)
예제 #6
0
 def __init__(self, log_dir):
     self.logger = Logger(log_dir)
     self.registered_models = []
     self.step_dict = {}