import project.config.globals as globals
logger=globals['logger']
class HelperClass(object):
def testFunction(self):
logger.trace("Log this statement")
I also tried to use the logger variable directly from the config script definition, but that didnât work either so I tried the dictionary approach as sited by pturmel.
Edit:
Function definition corrected. I removed the content of the class for the example pasted here. The use details are from a button action script:
import project.Helpers as Helpers
test=Helpers.HelperClass()
test.testFunction()
Is this the entire script? I see no instantiation of the class or call to the function, so I wouldnât expect it to actually log anything
Be careful with scoping.
Iâm not completely certain but unless you are intending to make HelperClass a subclass of âobjectâ, then your class signature is incorrect.
You will probably be required to include a âselfâ parameter in the function call
I would tend to write your class like this to ensure scoping is valid:
import project.config.globals as globals
class HelperClass():
_logger=globals['logger']
def testFunction(self,object):
_logger.trace('Log this statement')
#Then at some other point in the script
HelperClass.testFunction(object)
Depending on where you are looking for the log message to be, I assume the client or the designer, ensure that the logging level is set to trace, otherwise you will not see the log. The default logging level of the console in the designer is info, so you will not see a message in the console of the designer if you are using trace, however, if you are looking in the client then you should be able to see them so long as the logging level is set correctly.
By default the logging level is set at Info, so Trace and Debug logs are dropped. Try using info and see if the message shows up as you would expect.
import project.config.globals as globals
logger=globals['logger']
class HelperClass(object):
def testFunction(self):
logger.info('Log this statement')
How can I get into the system logs if this is running as a shared script? It the object instantiation on the client and that is why it is failing to so into the system logs (gateway page --> status --> logs)?
The logger name I have set is not available, so no entries have been made? I canât se the level until at least one entry is made. I have some info-level entries in the real application which should be included with the default settings.
Shared scripts don't automatically run on the gateway - they're just able to be called from any scope. You would have to run whatever event you're actually running on the gateway to directly use system.util.getLogger and have it show up in the gateway logs.