Skip to content

Commit

Permalink
Log: update the fretwork log module
Browse files Browse the repository at this point in the history
The idea is to use the python logging module to manage logs.
  • Loading branch information
Linkid committed Nov 25, 2017
1 parent 7afe2ab commit cde5aa7
Show file tree
Hide file tree
Showing 35 changed files with 168 additions and 80 deletions.
24 changes: 13 additions & 11 deletions FoFiX.py
Expand Up @@ -36,6 +36,8 @@
import platform
import subprocess
import atexit
import logging


def run_command(command):
command = command.split(' ')
Expand Down Expand Up @@ -120,12 +122,13 @@ def cmd_args():
if os.name == "posix":
# Under MacOS X, put the logs in ~/Library/Logs
if os.uname()[0] == "Darwin":
logFile = open(os.path.expanduser('~/Library/Logs/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME), 'w')
logfile = os.path.expanduser('~/Library/Logs/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME)
else: # GNU/Linux et al.
logFile = VFS.open('/userdata/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME, 'w')
logfile = VFS.resolveWrite('/userdata/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME)
else:
logFile = VFS.open('/userdata/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME, 'w')
log.setLogfile(logFile)
logfile = VFS.resolveWrite('/userdata/%s.log' % Version.PROGRAM_UNIXSTYLE_NAME)
log.configure(logfile)
logger = logging.getLogger(__name__)

fretworkRequired = (0, 2, 0)
reqVerStr = '.'.join([str(i) for i in fretworkRequired])
Expand Down Expand Up @@ -220,7 +223,7 @@ def load_config(configPath):
return config

def restart(self):
log.info("Restarting.")
logger.info("Restarting.")
self.engine.audio.close()
self.restartRequested = True

Expand All @@ -233,7 +236,7 @@ def run(self):
try:
vidPlayer = VideoLayer(self.engine, vidSource, cancellable=True)
except (IOError, VideoPlayerError):
log.error("Error loading intro video:")
logger.error("Error loading intro video:")
else:
vidPlayer.play()
self.engine.view.pushLayer(vidPlayer)
Expand All @@ -253,7 +256,7 @@ def run(self):
while self.engine.run():
pass
except KeyboardInterrupt:
log.info("Left mainloop due to KeyboardInterrupt.")
logger.info("Left mainloop due to KeyboardInterrupt.")
# don't reraise

# Restart the program if the engine is asking that we do so.
Expand All @@ -276,8 +279,8 @@ def run(self):
except (KeyboardInterrupt, SystemExit):
raise
except Exception:
log.error("Terminating due to unhandled exception: ")
_logname = os.path.abspath(log.logFile.name)
logger.error("Terminating due to unhandled exception: ")
_logname = os.path.abspath(logfile)
_errmsg = "%s\n\n%s\n%s\n%s\n%s" % (
_("Terminating due to unhandled exception:"),
traceback.format_exc(),
Expand All @@ -290,10 +293,9 @@ def run(self):
import win32api
import win32con
if win32api.MessageBox(0, "%s\n\n%s" % (_errmsg, _("Open the logfile now?")), "%s %s" % (Version.PROGRAM_NAME, Version.version()), win32con.MB_YESNO|win32con.MB_ICONSTOP) == win32con.IDYES:
log.logFile.close()
os.startfile(_logname)
if hasattr(sys, 'frozen'):
sys.exit(1) # don't reraise if py2exe'd so the "Errors occurred" box won't appear after this and confuse the user as to which logfile we actually want
else:
print >>sys.stderr, _errmsg
logger.error(_errmsg)
raise
4 changes: 3 additions & 1 deletion fofix/core/Config.py
Expand Up @@ -23,15 +23,17 @@
# MA 02110-1301, USA. #
#####################################################################

import logging
import os
import StringIO
from ConfigParser import RawConfigParser

from fretwork import log
from fretwork.unicode import utf8, unicodify

from fofix.core import VFS


log = logging.getLogger(__name__)
config = None
prototype = {}

Expand Down
7 changes: 5 additions & 2 deletions fofix/core/Data.py
Expand Up @@ -23,20 +23,23 @@
# MA 02110-1301, USA. #
#####################################################################

import logging
import os
import glob
import random

from fretwork import log
from fretwork.audio import Sound

from fofix.core.Font import Font
from fofix.core.Image import ImgDrawing

from fofix.core import Config
from fofix.core import Version
from fofix.core import Player


log = logging.getLogger(__name__)


# these constants define a few customized letters in the default font
# MFH - with the new simplified Font.py, no more custom glyphs... let's do
# a simple replacement here for now...
Expand Down
8 changes: 4 additions & 4 deletions fofix/core/GameEngine.py
Expand Up @@ -37,15 +37,14 @@
import os
import sys
import imp
import logging

from fretwork import log
from fretwork.audio import Audio
from fretwork.task import TaskEngine
from fretwork.timer import FpsTimer

from fofix.core.constants import *
from fofix.core.Video import Video

from fofix.core.View import View
from fofix.core.Input import Input, KeyListener, SystemEventListener
from fofix.core.Resource import Resource
Expand All @@ -55,18 +54,19 @@
from fofix.core.Theme import Theme
from fofix.core.Shader import shaders
from fofix.core.Image import drawImage

from fofix.core import cmgl
from fofix.core import Config
from fofix.core import ConfigDefs
from fofix.core import Version
from fofix.core import Player
from fofix.core import Mod
from fofix.game import Dialogs

from fofix.game.World import World
from fofix.game.Debug import DebugLayer


log = logging.getLogger(__name__)

# evilynux - Grab name and version from Version class.
version = "%s v%s" % ( Version.PROGRAM_NAME, Version.version() )

Expand Down
7 changes: 5 additions & 2 deletions fofix/core/Image.py
Expand Up @@ -21,18 +21,21 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, #
# MA 02110-1301, USA. #
#####################################################################

from __future__ import with_statement
import logging

import numpy as np
from PIL import Image
from OpenGL.GL import *

from fretwork import log

from fofix.core.Texture import Texture
from fofix.core.constants import *
from fofix.core import cmgl


log = logging.getLogger(__name__)

#stump: the last few stubs of DummyAmanith.py are inlined here since this
# is the only place in the whole program that uses it now that we've pruned
# the dead SVG code.
Expand Down
9 changes: 8 additions & 1 deletion fofix/core/Input.py
Expand Up @@ -22,8 +22,11 @@
# MA 02110-1301, USA. #
#####################################################################

import logging
import pygame


log = logging.getLogger(__name__)
haveMidi = False

try:
Expand All @@ -32,14 +35,14 @@
except ImportError:
haveMidi = False

from fretwork import log
from fretwork.audio import Music
from fretwork.task import Task

from fofix.core.Player import Controls
from fofix.core import Player
from fofix.core import Config


class KeyListener(object):
def keyPressed(self, key, unicode):
pass
Expand All @@ -53,6 +56,7 @@ def lostFocus(self):
def exitRequested(self):
pass


class MouseListener(object):
def mouseButtonPressed(self, button, pos):
pass
Expand All @@ -63,6 +67,7 @@ def mouseButtonReleased(self, button, pos):
def mouseMoved(self, pos, rel):
pass


class SystemEventListener(object):
def screenResized(self, size):
pass
Expand All @@ -76,8 +81,10 @@ def musicFinished(self):
def quit(self):
pass


MusicFinished = pygame.USEREVENT


class Input(Task):
def __init__(self):

Expand Down
7 changes: 5 additions & 2 deletions fofix/core/Language.py
Expand Up @@ -19,20 +19,23 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, #
# MA 02110-1301, USA. #
#####################################################################

from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import gettext
import glob
import logging
import os

from fretwork import log

from fofix.core import Version
from fofix.core import Config


log = logging.getLogger(__name__)


def getAvailableLanguages():
return [os.path.basename(l).capitalize().replace(".mo", "").replace("_", " ") for l in glob.glob(os.path.join(Version.dataPath(), "translations", "*.mo"))]

Expand Down
6 changes: 4 additions & 2 deletions fofix/core/Microphone.py
Expand Up @@ -21,15 +21,17 @@
# MA 02110-1301, USA. #
#####################################################################

import logging
import math
import numpy as np

from fretwork import log
import numpy as np
from fretwork.task import Task
from fretwork.audio import MicrophonePassthroughStream

from fofix.core.Language import _

log = logging.getLogger(__name__)

try:
import pyaudio
from fofix.core import pypitch
Expand Down
7 changes: 5 additions & 2 deletions fofix/core/Mod.py
Expand Up @@ -20,14 +20,17 @@
# MA 02110-1301, USA. #
#####################################################################

import logging
import os

from fretwork import log

from fofix.core.Language import _
from fofix.core import Config
from fofix.core import Theme


log = logging.getLogger(__name__)


def _getModPath(engine):
return engine.resource.fileName("mods")

Expand Down
8 changes: 6 additions & 2 deletions fofix/core/Player.py
Expand Up @@ -24,16 +24,20 @@
# MA 02110-1301, USA. #
#####################################################################

import pygame
import logging

from fretwork import log
import pygame

from fofix.core.Language import _
from fofix.core import Microphone #stump
from fofix.core import Config
from fofix.game import song
from fofix.core import VFS


log = logging.getLogger(__name__)


class ConfigOption:
def __init__(self, id, text):
self.id = id
Expand Down
6 changes: 5 additions & 1 deletion fofix/core/Resource.py
Expand Up @@ -22,6 +22,7 @@
# MA 02110-1301, USA. #
#####################################################################

import logging
import os
import sys
import time
Expand All @@ -30,13 +31,16 @@
from Queue import Queue, Empty
from threading import Thread, BoundedSemaphore

from fretwork import log
from fretwork.task import Task

from fofix.core.VFS import getWritableResourcePath
from fofix.core import Version
from fofix.core import Config


log = logging.getLogger(__name__)


class Loader(Thread):
def __init__(self, target, name, function, resultQueue, loaderSemaphore, onLoad = None, onCancel = None):
Thread.__init__(self)
Expand Down
7 changes: 5 additions & 2 deletions fofix/core/Settings.py
Expand Up @@ -29,12 +29,11 @@
# MA 02110-1301, USA. #
#####################################################################

import logging
import os

import pygame

from fretwork import log

from fofix.core.Language import _
from fofix.core.View import BackgroundLayer
from fofix.core.Input import KeyListener
Expand All @@ -47,6 +46,10 @@
from fofix.core import Mod
from fofix.core import VFS


log = logging.getLogger(__name__)


class ConfigChoice(Menu.Choice):
def __init__(self, engine, config, section, option, autoApply = False, isQuickset = 0):
self.engine = engine
Expand Down

0 comments on commit cde5aa7

Please sign in to comment.