[request] want an option to append user logs to existing file --- workaround for P(J)ython scripts

Bug #1523582 reported by RaiMan
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
SikuliX
In Progress
Medium
RaiMan

Bug Description

Is there an option for write into a log file without overwriting the file? Sikuli 1.1.0
My script looks like:
Settings.UserLogs=True
Settings.UserLogPrefix="Alexander"
Settings.UserLogTime=True
Debug.setUserLogFile("path\MyLogs.txt")
Debug.user("text")

Revision history for this message
RaiMan (raimund-hocke) wrote :

not possible with version 1.1.x.

accepted for version 2

Changed in sikuli:
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 2.0.0
Revision history for this message
Karl (k-d) wrote :

Here is a work-around for Python:

Put the following in a my_module.py in C:\Users\User\AppData\Roaming\Sikulix\Lib\site-packages and in sikuli scripts use from my_module import *:

#----------start of my_module.py----------#
from org.sikuli.basics import Debug as SikuliDebug
from org.sikuli.basics import Settings as SikuliSettings
import datetime

class Debug(SikuliDebug):
 printoutuser = None

 @staticmethod
 def setUserLogFile(fileName):
  if fileName == None:
   fileName = ""
  if fileName != None:
   if "" == fileName:
    if Settings.isMacApp:
     Debug.printoutuser = "UserLog.txt"
    else:
     Debug.printoutuser = getBundleFolder()+ "UserLog.txt"
   try:
    Debug.printoutuser = fileName
    with open(Debug.printoutuser, "a") as f:
     f.write("")
    return True
   except:
    print "[Error] User logfile %s not accessible - check given path"% fileName
    return False
  return False;

 @staticmethod
 def user(message):
  if SikuliSettings.UserLogs:
   with open(Debug.printoutuser, "a") as f:
    if SikuliSettings.UserLogTime:
     text = '[{} ({})] {}'.format(SikuliSettings.UserLogPrefix,'{:%m/%d/%y %I:%M:%S %p}'.format(datetime.datetime.now()).lstrip("0").replace(" 0", " "), message)
    else:
     text = '[{}] {}'.format(SikuliSettings.UserLogPrefix, message)
    f.write(text+"\n")
#----------end of my_module.py----------#

RaiMan (raimund-hocke)
summary: - [request] want an option to append user logs to existing file
+ [request] want an option to append user logs to existing file ---
+ workaround for P(J)ython scripts
RaiMan (raimund-hocke)
Changed in sikuli:
milestone: 2.0.0 → 2.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.