Skip to content

Commit

Permalink
Merge pull request #179 from nicolasbock/nicolasbock/issue177
Browse files Browse the repository at this point in the history
Move log file to more of a temporary location
  • Loading branch information
nicolasbock authored May 16, 2022
2 parents 6a29d21 + 5889f5a commit a891616
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
12 changes: 7 additions & 5 deletions ebuildtester/main.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from ebuildtester.docker import Docker, ExecuteFailure
from ebuildtester.parse import parse_commandline
import ebuildtester.options as options
import logging
import os.path
import sys


def main():
"""The main function."""

options.init()

options.log.setLevel(logging.DEBUG)

options.options = parse_commandline(sys.argv[1:])
if len(options.options.atom) > 0:
options.set_logfile('ebuildtester-'
+ ':'.join([f'{atom.category}-{atom.package}'
for atom in options.options.atom])
+ '.log')
else:
options.set_logfile('ebuildtester-manual.log')

options.log.info("creating container")
container = Docker(
Expand Down
42 changes: 25 additions & 17 deletions ebuildtester/options.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
"""Options and some initializations."""

from ebuildtester.atom import Atom
import logging
import os

base_packages = list(map(Atom, ["app-portage/gentoolkit",
"app-portage/flaggie"]))
options = None
log = logging.getLogger("test-package")
log_ch = logging.StreamHandler()
log_ch.setLevel(logging.INFO)
log_ch.setFormatter(logging.Formatter("%(asctime)s - %(message)s"))
log.addHandler(log_ch)
log.setLevel(logging.DEBUG)

logdir = os.getenv('XDG_STATE_HOME', '/tmp')
_logfile = None
_log_filehandle = None

def init():
global base_packages
global log
global log_ch
global options

base_packages = list(map(Atom, ["app-portage/gentoolkit",
"app-portage/flaggie"]))
options = None
log = logging.getLogger("test-package")
log_ch = logging.StreamHandler()
log_ch.setLevel(logging.INFO)
log_ch.setFormatter(logging.Formatter("%(asctime)s - %(message)s"))
log.addHandler(log_ch)
def set_logfile(logfile):
"""Add a logfile to logging."""

fh = logging.FileHandler("/tmp/ebuildtester.log", "a")
fh.setLevel(logging.INFO)
fh.setFormatter(logging.Formatter("%(asctime)s - %(message)s"))
log.addHandler(fh)
_logfile = os.path.join(logdir, logfile)
_log_filehandle = logging.FileHandler(_logfile, "a")
_log_filehandle.setLevel(logging.INFO)
_log_filehandle.setFormatter(
logging.Formatter("%(asctime)s - %(message)s"))
log.addHandler(_log_filehandle)
log.info("logging at %s", _logfile)

0 comments on commit a891616

Please sign in to comment.