summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xportato.py4
-rw-r--r--portato/__init__.py48
-rw-r--r--portato/gui/views.py2
-rw-r--r--portato/helper.py12
-rw-r--r--portato/log.py86
5 files changed, 100 insertions, 52 deletions
diff --git a/portato.py b/portato.py
index c2b861e..7b87262 100755
--- a/portato.py
+++ b/portato.py
@@ -20,7 +20,7 @@ import atexit
import gettext, locale
from optparse import OptionParser, SUPPRESS_HELP
-from portato import get_listener
+from portato import get_listener, log
from portato.helper import debug, info
from portato.constants import VERSION, LOCALE_DIR, APP, SU_COMMAND
@@ -49,6 +49,8 @@ def main ():
atexit.register(get_listener().close)
if options.nofork or os.getuid() == 0: # start GUI
+ log.start(file = True) # start logging to file
+
from portato.gui import run
info("%s v. %s", _("Starting Portato"), VERSION)
diff --git a/portato/__init__.py b/portato/__init__.py
index b5a9859..5d5cb22 100644
--- a/portato/__init__.py
+++ b/portato/__init__.py
@@ -12,52 +12,12 @@
from __future__ import absolute_import
-import logging
-import sys
-import os
+from . import log
-class OutputFormatter (logging.Formatter):
-
- colors = {
- "blue" : 34,
- "green" : 32,
- "red" : 31,
- "yellow": 33
- }
-
- def __init__(self, *args, **kwargs):
- logging.Formatter.__init__(self, *args, **kwargs)
-
- for key, value in self.colors.iteritems():
- self.colors[key] = "\x1b[01;%02dm*\x1b[39;49;00m" % value
-
- def format (self, record):
- string = logging.Formatter.format(self, record)
- color = None
-
- if os.isatty(sys.stderr.fileno()):
- if record.levelno <= logging.DEBUG:
- color = self.colors["blue"]
- elif record.levelno <= logging.INFO:
- color = self.colors["green"]
- elif record.levelno <= logging.WARNING:
- color = self.colors["yellow"]
- else:
- color = self.colors["red"]
- else:
- color = "%s:" % record.levelname
-
- return "%s %s" % (color, string)
-
-# set the whole logging stuff
-formatter = OutputFormatter("%(message)s (%(filename)s:%(lineno)s)")
-
-handler = logging.StreamHandler()
-handler.setFormatter(formatter)
-logging.getLogger("portatoLogger").addHandler(handler)
-logging.getLogger("portatoLogger").setLevel(logging.DEBUG)
-logging.getLogger("portatoLogger").propagate = False
+# start logging
+log.start(file=False)
+# listener-handling
__listener = None
def get_listener():
diff --git a/portato/gui/views.py b/portato/gui/views.py
index a2d0468..85a06c8 100644
--- a/portato/gui/views.py
+++ b/portato/gui/views.py
@@ -133,7 +133,7 @@ class LogView (logging.Handler):
for lvl, name, color in self.colors:
self.buf.create_tag("log_%s" % name, foreground = color,weight = pango.WEIGHT_BOLD)
- logging.getLogger("portatoLogger").addHandler(self)
+ logging.getLogger("portatoLogger.stream").addHandler(self)
def emit (self, record):
diff --git a/portato/helper.py b/portato/helper.py
index 2363adb..8a312c0 100644
--- a/portato/helper.py
+++ b/portato/helper.py
@@ -17,17 +17,17 @@ from __future__ import absolute_import
import os, signal, logging, grp
-debug = logging.getLogger("portatoLogger").debug
-info = logging.getLogger("portatoLogger").info
-warning = logging.getLogger("portatoLogger").warning
-error = logging.getLogger("portatoLogger").error
-critical = logging.getLogger("portatoLogger").critical
+debug = logging.getLogger("portatoLogger.stream").debug
+info = logging.getLogger("portatoLogger.stream").info
+warning = logging.getLogger("portatoLogger.stream").warning
+error = logging.getLogger("portatoLogger.stream").error
+critical = logging.getLogger("portatoLogger.stream").critical
def N_ (s):
return s
def set_log_level (lvl):
- logging.getLogger("portatoLogger").setLevel(lvl)
+ logging.getLogger("portatoLogger.stream").setLevel(lvl)
def send_signal_to_group (sig):
"""Sends a signal to all processes of our process group (w/o ourselves).
diff --git a/portato/log.py b/portato/log.py
new file mode 100644
index 0000000..971dddf
--- /dev/null
+++ b/portato/log.py
@@ -0,0 +1,86 @@
+# -*- coding: utf-8 -*-
+#
+# File: portato/log.py
+# This file is part of the Portato-Project, a graphical portage-frontend.
+#
+# Copyright (C) 2008 René 'Necoro' Neumann
+# This is free software. You may redistribute copies of it under the terms of
+# the GNU General Public License version 2.
+# There is NO WARRANTY, to the extent permitted by law.
+#
+# Written by René 'Necoro' Neumann <necoro@necoro.net>
+
+from __future__ import absolute_import
+
+import logging
+import sys
+import os
+
+from .constants import SESSION_DIR
+
+(S_NOT, S_STREAM_ONLY, S_BOTH) = range(3)
+
+started = S_NOT
+
+class OutputFormatter (logging.Formatter):
+
+ colors = {
+ "blue" : 34,
+ "green" : 32,
+ "red" : 31,
+ "yellow": 33
+ }
+
+ def __init__(self, *args, **kwargs):
+ logging.Formatter.__init__(self, *args, **kwargs)
+
+ for key, value in self.colors.iteritems():
+ self.colors[key] = "\x1b[01;%02dm*\x1b[39;49;00m" % value
+
+ def format (self, record):
+ string = logging.Formatter.format(self, record)
+ color = None
+
+ if os.isatty(sys.stderr.fileno()):
+ if record.levelno <= logging.DEBUG:
+ color = self.colors["blue"]
+ elif record.levelno <= logging.INFO:
+ color = self.colors["green"]
+ elif record.levelno <= logging.WARNING:
+ color = self.colors["yellow"]
+ else:
+ color = self.colors["red"]
+ else:
+ color = "%s:" % record.levelname
+
+ return "%s %s" % (color, string)
+
+def start(file = True):
+ global started
+
+ if started == S_BOTH: return
+
+ # logging: root (file)
+ if file:
+ if not (os.path.exists(SESSION_DIR) and os.path.isdir(SESSION_DIR)):
+ os.mkdir(SESSION_DIR)
+
+ formatter = logging.Formatter("%(levelname)-8s: %(message)s (%(filename)s:%(lineno)s)")
+ handler = logging.FileHandler(os.path.join(SESSION_DIR, "portato.log"), "w")
+ handler.setFormatter(formatter)
+ logging.getLogger("portatoLogger").addHandler(handler)
+
+ if started == S_NOT:
+ logging.getLogger("portatoLogger").setLevel(logging.DEBUG)
+ logging.getLogger("portatoLogger").propagate = False
+
+ # logging: stream
+ # this logger should be used
+ if started == S_NOT:
+ formatter = OutputFormatter("%(message)s (%(filename)s:%(lineno)s)")
+ handler = logging.StreamHandler()
+ handler.setFormatter(formatter)
+ logging.getLogger("portatoLogger.stream").addHandler(handler)
+ logging.getLogger("portatoLogger.stream").setLevel(logging.DEBUG)
+
+ started = S_BOTH if file else S_STREAM_ONLY