tidy up logging so that log isn't created in /fpdb/log/ unless it is being used

This commit is contained in:
sqlcoder 2010-02-01 21:03:51 +00:00
parent 7e5f63ce89
commit 86330e536a
5 changed files with 23 additions and 13 deletions

7
pyfpdb/Configuration.py Normal file → Executable file
View File

@ -38,6 +38,10 @@ from xml.dom.minidom import Node
import logging, logging.config
import ConfigParser
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
log = logging.getLogger("config")
##############################################################################
# Functions for finding config files and setting up logging
# Also used in other modules that use logging.
@ -138,8 +142,6 @@ def check_dir(path, create = True):
else:
return False
# find a logging.conf file and set up logging
log = get_logger("logging.conf", "config")
########################################################################
# application wide consts
@ -458,6 +460,7 @@ class Config:
self.dir_config = os.path.dirname(self.file)
self.dir_log = os.path.join(self.dir_config, 'log')
self.dir_database = os.path.join(self.dir_config, 'database')
self.log_file = os.path.join(self.dir_log, 'logging.out')
log = get_logger("logging.conf", "config", log_dir=self.dir_log)
# Parse even if there was no real config file found and we are using the example

View File

@ -41,6 +41,10 @@ import Queue
import codecs
import math
import logging
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
log = logging.getLogger("db")
# pyGTK modules
@ -52,7 +56,6 @@ import Tourney
import Charset
from Exceptions import *
import Configuration
log = Configuration.get_logger("logging.conf","db")
# Other library modules
@ -225,7 +228,7 @@ class Database:
def __init__(self, c, sql = None):
log = Configuration.get_logger("logging.conf", "db", log_dir=c.dir_log)
log.info("Creating Database instance, sql = %s" % sql)
log.debug("Creating Database instance, sql = %s" % sql)
self.config = c
self.__connected = False
self.settings = {}

View File

@ -26,13 +26,13 @@ import gtk
import gobject
import pango
import Configuration
import logging
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
log = logging.getLogger("logview")
log = Configuration.get_logger("logging.conf", "logview")
MAX_LINES = 100000 # max lines to display in window
EST_CHARS_PER_LINE = 150 # used to guesstimate number of lines in log file
logfile = 'logging.out' # name of logfile
class GuiLogView:
@ -41,6 +41,7 @@ class GuiLogView:
self.main_window = mainwin
self.closeq = closeq
self.logfile = self.config.log_file # name of logfile
self.dia = gtk.Dialog(title="Log Messages"
,parent=None
,flags=gtk.DIALOG_DESTROY_WITH_PARENT
@ -117,10 +118,10 @@ class GuiLogView:
self.listcols = []
# guesstimate number of lines in file
if os.path.exists(logfile):
stat_info = os.stat(logfile)
if os.path.exists(self.logfile):
stat_info = os.stat(self.logfile)
lines = stat_info.st_size / EST_CHARS_PER_LINE
print "logview: size =", stat_info.st_size, "lines =", lines
#print "logview: size =", stat_info.st_size, "lines =", lines
# set startline to line number to start display from
startline = 0
@ -129,7 +130,7 @@ class GuiLogView:
startline = lines - MAX_LINES
l = 0
for line in open(logfile):
for line in open(self.logfile):
# eg line:
# 2009-12-02 15:23:21,716 - config DEBUG config logger initialised
l = l + 1

View File

@ -117,7 +117,6 @@ import Exceptions
VERSION = "0.12"
log = Configuration.get_logger("logging.conf", "fpdb")
class fpdb:
def tab_clicked(self, widget, tab_name):
@ -696,6 +695,7 @@ class fpdb:
"""Loads profile from the provided path name."""
self.config = Configuration.Config(file=options.config, dbname=options.dbname)
log = Configuration.get_logger("logging.conf", "fpdb", log_dir=self.config.dir_log)
print "Logfile is " + os.path.join(self.config.dir_log, 'logging.out') + "\n"
if self.config.example_copy:
self.info_box( "Config file"
, "has been created at:\n%s.\n" % self.config.file

5
pyfpdb/fpdb_import.py Normal file → Executable file
View File

@ -30,6 +30,10 @@ import Queue
from collections import deque # using Queue for now
import threading
import logging
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
log = logging.getLogger("importer")
import pygtk
import gtk
@ -39,7 +43,6 @@ import Database
import Configuration
import Exceptions
log = Configuration.get_logger("logging.conf", "importer")
# database interface modules
try: