Commit 18c00d60 authored by Bartek Górny's avatar Bartek Górny

log function prints caller's name (from stack analysis)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9788 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 84b61184
......@@ -35,7 +35,7 @@ import ERP5Defaults
from zLOG import LOG, INFO
from string import join
import os
import os, traceback
MARKER = []
......@@ -850,10 +850,19 @@ class ERP5Site(FolderMixIn, CMFSite):
new_instance.immediateReindexObject()
return new_instance
def log(self,description,content):
def log(self,description,content=''):
"""
Put a log message
"""
if content=='': # allow for content only while keeping interface
description,content=content,description
st=traceback.extract_stack()
head=[]
for frame in st[-2:-6:-1]: # assume no deep nesting in Script (Python)
if frame[0]=='Script (Python)': # does anybody log from ZPT or dtml?
head.append('%s, %d' % (frame[2],frame[1]))
head=' -> '.join(head)
description='%s: %s' % (head,description)
LOG(description, 0, content)
......
......@@ -66,6 +66,7 @@ import sys
import pickle
import copy
import psyco
import traceback
from cStringIO import StringIO
from email.MIMEBase import MIMEBase
......@@ -2131,9 +2132,21 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
return getattr(self,'title',None)
security.declarePublic('log')
def log(self, subsystem, message, level=INFO):
def log(self, description, content, level=INFO):
"""Put a log message """
LOG(subsystem, level, message)
if content=='': # allow for content only while keeping interface
description,content=content,description
st=traceback.extract_stack()
head=[]
for frame in st[-2:-6:-1]: # assume no deep nesting in Script (Python)
if frame[3] is not None and frame[3].startswith('self.log'): # called from class
head.append('%s, %d' % (frame[2],frame[1]))
break
if frame[0]=='Script (Python)': # does anybody log from ZPT or dtml?
head.append('%s, %d' % (frame[2],frame[1]))
head=' -> '.join(head)
description='%s: %s' % (head,description)
LOG(description, level, content)
# Dublin Core Emulation for CMF interoperatibility
# CMF Dublin Core Compatibility
......
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