def test_console(): log = logging.Log() print_messages(log) # Check for existence of log file; no log file should exist with pytest.raises(Exception): a = log['_log_file_path']
def test_log_level(): remove_log_folder() # This test will suppress Debug messages log = logging.Log(log_level=20) print_messages(log) # Check existence of log files - nothing should exists since it's console only with pytest.raises(Exception): a = log['_log_file_path'] remove_log_folder()
def test_rotating(): remove_log_folder() log = logging.Log(__file__, rotating=True, console=False) log.start() for i in range(0, 40000): log.info(i) log.end() # find the directory listing files = os.listdir(log._log_dir) valid = False if len(files) > 1: valid = True assert valid remove_log_folder()
import os import atexit from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from audcon import configuration from gpm import logging app = Flask(__name__) app.config.from_object(configuration.cfg) db = SQLAlchemy(app) migrate = Migrate(app, db) log = logging.Log(script=os.path.join( os.path.dirname(os.path.abspath(__file__)), 'audcon.py'), log_level=10, rotating=True) log.info('init') from audcon import views, models # Schedule scanner and converter from apscheduler.schedulers.background import BackgroundScheduler from audcon.modules import scanner, converter scheduler = BackgroundScheduler(daemon=True) scheduler.add_job(scanner.scan, trigger="interval", minutes=15) scheduler.add_job(converter.convert, trigger="interval", minutes=60) scheduler.start() # Shut down the scheduler when exiting the app atexit.register(lambda: scheduler.shutdown())
import os import gzip from gpm import config, logging, formatting from gpm import os as gpmos cfg = config.Config(script=__file__, create=True) cfg.read() log = logging.Log(script=__file__, log_level=cfg.LOG_LEVEL, log_entry_format_separator=cfg.LOG_ENTRY_SEPARATOR, tsformat='YYYYMMDD') def do(): errcode = 0 # Check backup dir, if it does not exist, create it if not os.path.exists(cfg.BACKUP_DIR): os.mkdir(cfg.BACKUP_DIR) # Configure commands mysqlcliauth = "--host={host} --port={port} --user={user} --password={passw}" mysqlclidocker = "docker run --network=host -i {image}" mysqlcliauth = mysqlcliauth.format( host=cfg.MYSQL['HOST'], port=cfg.MYSQL['PORT'], user=cfg.MYSQL['USER'], passw=cfg.MYSQL['PASSW'], )
def test_file_tsformat_keyword(): remove_log_folder() log = logging.Log(__file__, tsformat='YYYYMMDD', keyword='test/') print_messages(log) assert log._log_file_path remove_log_folder()
def test_file_no_tsformat(): remove_log_folder() log = logging.Log(__file__) print_messages(log) assert log._log_file_path remove_log_folder()
round(download_rate_files, 2), formatting.fsize_pretty(download_rate_gb))) log.info('est. number of files remaining: {}'.format( files_remaining)) log.info('est. time remaining: {}'.format( formatting.time_pretty(time_remaining))) log.info('est. size remaining: {}'.format( formatting.fsize_pretty(size_remaining))) page_num += 1 else: log.error('error occurred connecting to url {}'.format(url)) return err if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('site', choices=['alphacoder'], help='site identifier') parser.add_argument( '--download_dir', help='full path of the target folder to save images to') args = parser.parse_args() log = logging.Log(log_level=c.log_level, script=__file__) log.start() errcode = do(site=args.site, download_dir=args.download_dir) log.end() exit(errcode)