def test_logger(self): # configurer the logger #log.configure(self.logfile.name, logging.INFO) log.configure(self.logfile.name) self.assertTrue(os.path.exists(self.logfile.name)) # log a message logger = logging.getLogger(__name__) msg = "Test info log" logger.info(msg) # read the log file log_msg = self.logfile.readline().decode() self.assertIn('INFO', log_msg) self.assertIn(msg, log_msg)
def test_logger_warning_level(self): # configurer the logger in Warning level #log.configure(self.logfile.name, logging.WARNING) log.configure(self.logfile.name, 'WARNING') # log two messages logger = logging.getLogger(__name__) msg_info = "Test info log" msg_warning = "Test warning log" logger.info(msg_info) logger.warning(msg_warning) # read the log file log_msgs = self.logfile.readlines() self.assertEqual(len(log_msgs), 1) log_msg = log_msgs[0].decode() # check the log file content self.assertNotIn('INFO', log_msg) self.assertNotIn(msg_info, log_msg) self.assertIn('WARNING', log_msg) self.assertIn(msg_warning, log_msg)
# This must be before *anything* that may import pyOpenGL! if not args['gl_error_check']: disable_gl_checks() # setup the logfile # File object representing the logfile if is_macos: # Under MacOS X, put the logs in ~/Library/Logs logfile = os.path.expanduser('~/Library/Logs/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME) else: # Unix: ~/.fofix/ logfile = VFS.resolveWrite('/userdata/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME) log.configure(logfile) logger = logging.getLogger(__name__) # Imports import fretwork from fofix.game.Main import Main from fofix.core.Language import _ # This prevents the following message being displayed on macOS: # ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to *path* if is_macos: data = run_command( 'defaults read org.python.python ApplePersistenceIgnoreState') if data in ['1', 'ON']: run_command( 'defaults write org.python.python ApplePersistenceIgnoreState 0'
from fretwork import log from fofix.core import Version from fofix.core import VFS # setup the logfile # logfile in ~/.fofix/ for GNU/Linux and MacOS X if os.name == "posix": # Under MacOS X, put the logs in ~/Library/Logs if os.uname()[0] == "Darwin": logfile = os.path.expanduser('~/Library/Logs/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME) else: # GNU/Linux et al. logfile = VFS.resolveWrite('/userdata/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME) else: logfile = VFS.resolveWrite('/userdata/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME) log.configure(logfile) logger = logging.getLogger(__name__) fretworkRequired = (0, 4, 0) reqVerStr = '.'.join([str(i) for i in fretworkRequired]) fretworkErrorStr = ''' The version of fretwork installed is old. Please install the latest version from github. https://github.com/fofix/fretwork/releases/ Installed: {0} Required: {1} ''' # The first version of fretwork didnt have __version__ if hasattr(fretwork, '__version__'): version = fretwork.__version__.split('-')[0] # remove 'dev' from ver version = tuple([int(i) for i in version.split('.')])
import tempfile from fretwork import log # set log file fp = tempfile.NamedTemporaryFile(delete=True) log.configure(fp.name)