clenaup logging in emulator, cleanup emulator in main script

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2013-09-02 10:49:11 +02:00
parent 760b7e7afb
commit 93f5ace932
2 changed files with 4 additions and 23 deletions

View file

@ -63,18 +63,6 @@ class Emulator(object):
self.__init_log()
def filter(self, record):
"""Add hostname and object to logs via logging Filter"""
prefix = self.target_host + ": (emulator)"
prefix = '{0}: emulator {1}'.format(
self.target_host,
core.CdistObject.join_name(self.type_name, self.object_id)
)
record.msg = prefix + ": " + record.msg
return True
def run(self):
"""Emulate type commands (i.e. __file and co)"""
@ -87,16 +75,13 @@ class Emulator(object):
def __init_log(self):
"""Setup logging facility"""
logformat = '%(levelname)s: %(message)s'
logging.basicConfig(format=logformat)
if '__cdist_debug' in self.env:
logging.root.setLevel(logging.DEBUG)
else:
logging.root.setLevel(logging.INFO)
self.log = logging.getLogger(__name__)
self.log.addFilter(self)
self.log = logging.getLogger(self.target_host)
def commandline(self):
"""Parse command line"""

View file

@ -122,12 +122,6 @@ def commandline():
args.func(args)
def emulator():
"""Prepare and run emulator"""
import cdist.emulator
emulator = cdist.emulator.Emulator(sys.argv)
return emulator.run()
if __name__ == "__main__":
# Sys is needed for sys.exit()
import sys
@ -153,7 +147,9 @@ if __name__ == "__main__":
log = logging.getLogger("cdist")
if re.match("__", os.path.basename(sys.argv[0])):
emulator()
import cdist.emulator
emulator = cdist.emulator.Emulator(sys.argv)
emulator.run()
else:
commandline()