← Back to team overview

sikuli-driver team mailing list archive

[Question #173063]: Is there any import files which we use to create a custom log file like the Tempfile module

 

New question #173063 on Sikuli:
https://answers.launchpad.net/sikuli/+question/173063

Hi 
   I have one logger function which will create a log file in the temp folder.But i would like to create the log file in the current working directory (getBundlePath()). is there any specific module which will create it into the working directory

import os
import sys 
import logging
import tempfile
import time


class Logger:
	"""
	logging package with test specific log file information
	"""
	
	def __init__(self, path=0, debug=0, suffix=0, prefix=0, dir=0):
		"""
		Initialize a log file
		"""
		#tempfile = getBundlePath()
		
		print "In logger"
		self.startTime = time.localtime()
		if debug:
			self.logLevel = logging.DEBUG
		else:
			self.logLevel = logging.INFO
		self.logFilePrefix = None
		self.logFilePath = None
		self.logFileDir = None
		self.logFileSuffix = None
		self.__initTempFile(path, suffix, prefix, dir)
		self.name = "GDTTUL" # trying to keep it short
		self.log = None
		self.logFileHandle = None
		self.__initLocalLogFile()
		self.log.info("Start of logging with new basic Config")
		self.log.info("Log file path: " + self.logFilePath)
		self.log.info("Log Level: ")
		self.log.info(self.logLevel)
		self.log.info("Host Name: " + os.name)
		self.log.info(self.startTime)
		self.__initNetLogConnection()

	def __initTempFile(self, path, suffix, prefix, dir):
		if prefix: self.logFilePrefix = prefix
		if path: self.logFilePath = path
		if dir: self.logFileDir = dir
		if suffix: self.logFileSuffix = suffix

	def __initLocalLogFile(self):
		"""
		Initialize the local log file for this test session
		"""
		if not self.logFilePath:
			self.__initLogFile()
		# self.log.info
		logging.basicConfig(filename = self.logFilePath, level = self.logLevel)
		self.log = logging.getLogger()

	def __initLogFile(self):
		"""
		Construct full path to a uniquely id'd log file
		for the current process
		Taken from the Jython 2.5.2 documentation for mkstemp,
		the basis for __initLogFile (and Utils.tempFile())

		'If suffix is specified, the file name will end with that suffix,
		otherwise there will be no suffix.
		mkstemp() does not put a dot between the file name and the suffix;
			if you need one, put it at the beginning of suffix.
		If prefix is specified, the file name will begin with that prefix;
			otherwise, a default prefix is used.
		If dir is specified, the file will be created in that directory;
			otherwise, a default directory is used. The default directory is
			chosen from a platform-dependent list, but the user of the
			application can control the directory location by setting the
			TMPDIR, TEMP or TMP environment variables. There is thus no
			guarantee that the generated filename will have any nice
			properties, such as not requiring quoting when passed to
			external commands via os.popen().'
		"""
		if not self.logFileSuffix: self.logFileSuffix = ".log"
		if not self.logFilePrefix:
			myBasename = os.path.basename(sys.argv[0])
			(myPrefix, mySuffix ) = os.path.splitext(myBasename)
			self.logFilePrefix = myPrefix
		if not self.logFileDir:
			(self.logFileHandle, self.logFilePath) = (suffix = self.logFileSuffix, prefix = self.logFilePrefix)
		else:
			(self.logFileHandle, self.logFilePath) = tempfile.mkstemp(suffix = self.logFileSuffix, prefix = self.logFilePrefix, dir = self.logFileDir)

	def __initNetLogConnection(self):
		"""
		TBD: what protocol does gdt want
		"""


-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.