Commit 1e7a8842 authored by Antoine Catton's avatar Antoine Catton

Simplelogger recipe now log in only one file (easier to rotate)

parent 06ec72b0
...@@ -24,31 +24,24 @@ ...@@ -24,31 +24,24 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
import shutil
import os
import sys import sys
import time import time
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
def log(args): def log(args):
directory, suffix = args prefix = time.strftime('%Y-%m-%d.%H:%M.%s:')
filename = time.strftime('%Y-%m-%d.%H:%M.%s') + suffix with open(args['filename'], 'aw') as logfile:
with open(os.path.join(directory, filename), 'aw') as logfile: for line in sys.stdin:
shutil.copyfileobj(sys.stdin, logfile) print >> logfile, prefix, line
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
def install(self): def install(self):
self.logger.info("Simple logger installation") wrapper = self.options['wrapper']
binary = self.options['binary'] log = self.options['log']
output = self.options['output']
suffix = self.options.get('suffix', '.log')
script = self.createPythonScript(binary,
'slapos.recipe.simplelogger.log',
arguments=[output, suffix])
self.logger.debug("Logger script created at : %r", script)
self.logger.info("Simple logger installed.")
script = self.createPythonScript(wrapper,
__name__ + '.log',
arguments=dict(filename=log))
return [script] return [script]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment