Jython - Creating Worklog object

Hi,

We are trying to get Worklog updated on a post function transition through one of our workflows.
Currently we managed to get the time spent field updated, but we are having trouble getting the whole worklog object and completing it.
Please see below the current Jython code we have:

from com.atlassian.jira.component import ComponentAccessor
from com.atlassian.jira.issue import Issue
import com.atlassian.jira.issue.history.ChangeItemBean

times=[]
diff=[]
user = ComponentAccessor.getJiraAuthenticationContext().getUser()
utils = ComponentAccessor.getJiraDurationUtils()
locale = ComponentAccessor.getLocaleManager().getLocaleFor(user)
changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

firstStart=changeHistoryManager.getChangeItemsForField(issue, "status")
for y in firstStart:
  if y.getToString()=="Handling":
    times.append({'s':"start", 't': y.getCreated().getTime()})
  if y.getFromString()=="Handling":
    times.append({'s': "end", 't': y.getCreated().getTime()})

times=sorted(times, key=lambda t: t['t'])
for t in times:
  if t['s']=='start':
    r=t['t']
  if t['s']=='end':
    diff.append(t['t']-r)

total=reduce(lambda x,y: x+y, diff)
issue.setTimeSpent(total/1000)

Thanks for any assistance!