This repository has been archived on 2021-03-01. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
kaneton/test/packages/ktp/log.py
Mercier Pierre-Olivier fee4dd4e6d Initial snapshot
2013-02-11 22:04:30 +01:00

50 lines
1 KiB
Python

#
# ---------- header -----------------------------------------------------------
#
# project kaneton
#
# license kaneton
#
# file /home/mycure/KANETON-TEST-SYSTEM/packages/ktp/log.py
#
# created julien quintard [mon oct 25 19:58:10 2010]
# updated julien quintard [tue mar 8 11:49:26 2011]
#
#
# ---------- packages ---------------------------------------------------------
#
import os
import time
import fcntl
#
# ---------- definitions ------------------------------------------------------
#
Extension = ".log"
#
# ---------- functions --------------------------------------------------------
#
#
# this function records the given message within the current log file.
#
def Record(directory, message):
handle = None
header = None
path = None
path = directory + "/" + time.strftime("%Y%m%d") + Extension
header = time.strftime("[%Y/%m/%d %H:%M:%S] ")
handle = open(path, "a")
fcntl.flock(handle.fileno(), fcntl.LOCK_EX)
handle.write(header + message + "\n")
handle.close()