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 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import shutil
import os
import sys
import time
from slapos.recipe.librecipe import GenericBaseRecipe
def log(args):
directory, suffix = args
filename = time.strftime('%Y-%m-%d.%H:%M.%s') + suffix
with open(os.path.join(directory, filename), 'aw') as logfile:
shutil.copyfileobj(sys.stdin, logfile)
prefix = time.strftime('%Y-%m-%d.%H:%M.%s:')
with open(args['filename'], 'aw') as logfile:
for line in sys.stdin:
print >> logfile, prefix, line
class Recipe(GenericBaseRecipe):
def install(self):
self.logger.info("Simple logger installation")
binary = self.options['binary']
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.")
wrapper = self.options['wrapper']
log = self.options['log']
script = self.createPythonScript(wrapper,
__name__ + '.log',
arguments=dict(filename=log))
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