def get_logger(arg_name): """ Called when the signal processing functions are being loaded by Python. Each call returns a logger object whose level will be updated later. Successive calls build up 2 singleton lists: logger_list and logger_name_list. """ logger = Logger(arg_name) logger.level = logbook.WARNING logger_name_list.append(arg_name) logger_list.append(logger) return logger
def init_logger(level=logbook.INFO): logbook.set_datetime_format("local") system_log = Logger("system_log") system_log.handlers = [] system_log.handlers.append(log_file_debug) system_log.handlers.append(log_file_info) system_log.handlers.append(log_file_err) system_log.handlers.append(std_handler) system_log.level = level return system_log
"""Benchmarks too low logger levels""" from logbook import Logger, StreamHandler, ERROR from cStringIO import StringIO log = Logger('Test logger') log.level = ERROR def run(): out = StringIO() with StreamHandler(out): for x in xrange(500): log.warning('this is not handled')
import os import platform import shutil from uuid import uuid4 from time import strftime import psutil from types import NoneType from logbook import FileHandler, Logger, CRITICAL log = Logger("Browser") if os.path.exists("application.log"): log_handler = FileHandler('application.log') log_handler.push_application() else: log.level = CRITICAL class Browser(object): def _expand(self, path): log.debug("Expanding: {}".format(path)) if self.os == "linux" or self.os == "darwin": return os.path.expanduser(path) elif self.os == "windows" and platform.release() != "XP": return os.path.expandvars(path) else: log.error("Unsupported OS: {} - expanding failed.".format(self.os)) return None def _backup_file(self, bak_dir, source_path, dest_name):
backup_browser = os.path.basename(restore_path)[0].lower() if backup_browser == browser.name: browser.restore_from_self(restore_path) else: restore_browser = self.all_browsers[backup_browser] restore_data = restore_browser.get_data(restore_path) browser.set_data(restore_data) if __name__ == '__main__': if os.path.exists("application.log"): log_handler = FileHandler('application.log') log_handler.push_application() else: log.level = CRITICAL parser = argparse.ArgumentParser(prog='RESTool Command Line Interface. ' 'See github for usage examples.') parser.add_argument( '-l', '--list', action='store_true', help= "List all available browsers and profiles to use for other commands.") parser.add_argument( '-b', '--backup', action='store_true', help=
# Copyright 2019 The Matrix.org Foundation CIC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import logbook from logbook import Logger logger = Logger("pantalaimon") logger.level = logbook.WARNING
from tortoise import Tortoise from alarmbot.loghandlers import ColorizedStderrHandler from alarmbot.models import init_db from alarmbot.receptionist import dp # Configure logging logger = Logger(__name__) logger.handlers.append(ColorizedStderrHandler()) async def init_orm(dispatcher): await init_db() async def close_orm(dispatcher): await Tortoise.close_connections() if __name__ == '__main__': logger.level = logbook.DEBUG logging.basicConfig(level=logging.INFO) loop = asyncio.get_event_loop() executor = Executor(dp, skip_updates=True, loop=loop) logger.info('{}', executor) executor.on_startup(init_orm, polling=True) executor.on_shutdown(close_orm, polling=True) # executor.set_webhook(web_app=app) # executor.run_app(port=8000) executor.start_polling()
"""Benchmarks too low logger levels""" from logbook import Logger, ERROR log = Logger('Test logger') log.level = ERROR def run(): for x in xrange(500): log.warning('this is not handled')
if __name__ == '__main__': opt = docopt(__doc__) D = DaqInterface(opt['--dev']); if opt['test']: print "Test Mode" resp = D.query('I',expected_text="cmd>") if not resp[0]: print resp[1] else: print "query command returned error code: ", resp[0] print "Full response: ", resp else: D.submit_to = opt['--submit_to'] D.start_thread() log.level = 2 to = time.time() try: while True: if not D.json_q.empty(): log.debug('Found items in Q') D.process_q() if time.time() - to > 30: D.send('A', CR=False) to = time.time() except KeyboardInterrupt: log.debug('Key pressed.') D.close() del(D) log.info('All Done.')
import os FILENAME = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'riurik-server.log') DJANGO_APP = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../', 'Riurik-Django-App/django-app.log') timeFormat = "%Y-%m-%d %H:%M:%S" try: from logbook import Logger log = Logger('logbook') log.level = logbook.DEBUG handler = logbook.RotatingFileHandler(filename=FILENAME, max_size=1024*1024*5, backup_count=10) handler.format_string = '{record.extra[localtime]} {record.time} [{record.process}:{record.thread}] ** {record.level_name} ** {record.message}' log.handlers.append(handler) except: import logging logging.basicConfig(filename=FILENAME, level=logging.DEBUG, format="%(asctime)s - %(message)s") log = logging.getLogger('default')