Hi,
I want to print the logs in gateway logs/gateway console to debug the code, but somehow I am unable to see these logs in gateway or gateway console.
I am doing it like below, please let me know what I am doing wrong here.
Thanks,
Anita
Hi,
I want to print the logs in gateway logs/gateway console to debug the code, but somehow I am unable to see these logs in gateway or gateway console.
I am doing it like below, please let me know what I am doing wrong here.
Thanks,
Anita
You need to create the LoggerEX
object first.
log = system.util.getLogger("Anita's Logger")
log.tracef("Calling replicateCallback..... ")
...
If that is a project library script, do the ...getLogger()
assignment outside the function, so it will be cached.
Do not use print
in gateway scope at all, unless you have easy admin access to the wrapper log file(s).
Edit: Uhm, the use of event.source
indicates this is Vision Client scope. Those only log to the local diagnostics page, not to the gateway.
How are we supposed to know that?
Post your whole code, where it's being executed, and more information about what's going wrong, or no one will be able to help you, because you haven't provided enough information.
I am trying to replicate the tags, I designer I have one button and we are using external python.
here is the button code in designer. I can see the print statements from button code.
here is one py file from here I am calling replicatecallback(),
this is the code upto replicatecallback function,
import system, sys, traceback, time
from ils.io.util import getTagExpression, getTagSQL, getUDTType, getTagScript, readTag, writeTag, isFolder, stripProvider
from ils.common.cast import listToDataset
COMMAND_TAG_PATH = "[Client]Replicate/Command"
DESTINATION_TAG_PROVIDER_TAG_PATH = "[Client]Replicate/Destination Tag Provider"
DUMP_TAGS_TAG_PATH = "[Client]Replicate/Dump Tags"
SELECTED_TAG_PATH_TAG_PATH = "[Client]Replicate/Selected Tag Path"
STATUS_TAG_PATH = "[Client]Replicate/Status"
TAG_COUNTER_TAG_PATH = "[Client]Replicate/Tag Counter"
TOTAL_TAG_COUNT_TAG_PATH = "[Client]Replicate/Total Tag Count"
REPLACE_EXPRESSION_TAGS_TAG_PATH = "[Client]Replicate/Replace Expression Tags"
REPLACE_QUERY_TAGS_TAG_PATH = "[Client]Replicate/Replace Query Tags"
ABORT_COMMAND = "Abort"
from ils.util.logging import getLogger
log = getLogger(name)
def internalFrameOpened(rootContainer):
log.infof("In %s.internalFrameOpened()", name)
projectName = system.util.getProjectName()
messageHandler = "getGatewayTagProviders"
tagProviders = system.util.sendRequest(projectName, messageHandler, scope = "G")
tagProviders.remove("System")
ds = listToDataset(tagProviders)
ds = system.dataset.sort(ds, 0)
rootContainer.TagProviders = ds
rootContainer.ShowPreferences = False
reset()
def abortCallback(event):
writeTag(COMMAND_TAG_PATH, ABORT_COMMAND)
def resetCallback(event):
reset()
def reset():
log.infof("In %s.reset()", name)
writeTag(COMMAND_TAG_PATH, "")
writeTag(STATUS_TAG_PATH, "")
writeTag(TOTAL_TAG_COUNT_TAG_PATH, 0)
writeTag(TAG_COUNTER_TAG_PATH, 0)
def replicateCallback(event):
log.tracef("Calling replicateCallback..... ")
log.infof("Calling replicateCallback..... ")
print "Calling replicateCallbackkkkkkkk..... "
rootContainer = event.source.parent
okToProceed, sourceTagProvider, destinationTagProvider, sourceTagTree, selectedTagPath = checkSelections(rootContainer)
log.infof('okToProceedddddddddd %s',okToProceed)
log.tracef('okToProceedddddddddd %s',okToProceed)
if not(okToProceed):
return
writeTag(SELECTED_TAG_PATH_TAG_PATH, selectedTagPath)
writeTag(DESTINATION_TAG_PROVIDER_TAG_PATH, destinationTagProvider)
writeTag(COMMAND_TAG_PATH, "Replicate")
Please edit your post to provide your code as preformatted text. See Wiki - how to post code on this forum.
You can edit your post by clicking the pencil Icon in the lower right of your post.
Also, if this is being run in a vision client then you will not see these logs in the gateway log, only the local client log.
I am unable to format the code, can you please help me by referring above two screenshots?
import system, sys, traceback, time
from ils.io.util import getTagExpression, getTagSQL, getUDTType, getTagScript, readTag, writeTag, isFolder, stripProvider
from ils.common.cast import listToDataset
COMMAND_TAG_PATH = "[Client]Replicate/Command"
DESTINATION_TAG_PROVIDER_TAG_PATH = "[Client]Replicate/Destination Tag Provider"
DUMP_TAGS_TAG_PATH = "[Client]Replicate/Dump Tags"
SELECTED_TAG_PATH_TAG_PATH = "[Client]Replicate/Selected Tag Path"
STATUS_TAG_PATH = "[Client]Replicate/Status"
TAG_COUNTER_TAG_PATH = "[Client]Replicate/Tag Counter"
TOTAL_TAG_COUNT_TAG_PATH = "[Client]Replicate/Total Tag Count"
REPLACE_EXPRESSION_TAGS_TAG_PATH = "[Client]Replicate/Replace Expression Tags"
REPLACE_QUERY_TAGS_TAG_PATH = "[Client]Replicate/Replace Query Tags"
ABORT_COMMAND = "Abort"
from ils.util.logging import getLogger
log = getLogger(name)
#log = system.util.getLogger(name)
def internalFrameOpened(rootContainer):
log.infof("In %s.internalFrameOpened()", name)
projectName = system.util.getProjectName()
messageHandler = "getGatewayTagProviders"
tagProviders = system.util.sendRequest(projectName, messageHandler, scope = "G")
tagProviders.remove("System")
ds = listToDataset(tagProviders)
ds = system.dataset.sort(ds, 0)
rootContainer.TagProviders = ds
rootContainer.ShowPreferences = False
def abortCallback(event):
writeTag(COMMAND_TAG_PATH, ABORT_COMMAND)
def resetCallback(event):
reset()
def reset():
log.infof("In %s.reset()", name)
writeTag(COMMAND_TAG_PATH, "")
writeTag(STATUS_TAG_PATH, "")
writeTag(TOTAL_TAG_COUNT_TAG_PATH, 0)
writeTag(TAG_COUNTER_TAG_PATH, 0)
def replicateCallback(event):
log.tracef("Calling replicateCallback..... ")
log.infof("Calling replicateCallback..... ")
print "Calling replicateCallbackkkkkkkk..... "
rootContainer = event.source.parent
okToProceed, sourceTagProvider, destinationTagProvider, sourceTagTree, selectedTagPath = checkSelections(rootContainer)
log.infof('okToProceedddddddddd %s',okToProceed)
log.tracef('okToProceedddddddddd %s',okToProceed)
if not(okToProceed):
return
writeTag(SELECTED_TAG_PATH_TAG_PATH, selectedTagPath)
writeTag(DESTINATION_TAG_PROVIDER_TAG_PATH, destinationTagProvider)
writeTag(COMMAND_TAG_PATH, "Replicate")
Also, you are in a project library script, don't import system
, its available by default.
In your event script on the component don't use import
, just do a single line call to the project library script function, like so: ils.common.tagReplicator.replicateCallback(event)
Did you read the linked post Wiki - how to post code on this forum? Please try again.
its not a project library, we are using external python here.
python code or replicatecallback() is outside the designer, because of that we are importing that library and then calling that function.
Well you can't be surprised that you don't see the logs in the gateway then...
What are you doing in this external script that you can't do in ignition ?
yes we can do it in ignition as well.
But its our work practice to write a code in external python file for version control.
Earlier I was able to see the logs in gateway, but now I did not understand why it is not showing.
I upgraded my code, earlier I was using ils.log now I am using ils.util.logger
is there anything I need to change in gateway configurations after changing the logger?
I don't see this function mentioned anywhere in your posted code...
okay, let me check
This whole thread seems to have missed that you are calling this code from the Designer (Button or Script Console) and that means the logs are going to appear in the Designer Console, not the Ignition Gateway logs.
No, I checked but logs not in desinger as well.
I am editing the py code in VS Code, my changes are saving in VS code but not reflecting in designer and client.
Earlier when I was saving something in VS code then desinger was blicking and client got restarted automatically.
But now its not notifying anything in designer and client.
I think issue is with VS code, any idea how to fix this and get desinger client and VS code in sync?
Please don't use external editors when trying to solve problems with us here on the forum. We can't reproduce your situation and therefore cannot effectively help you. Use just the designer while working through your code problem. You can resolve your external code editing situation after you have no other problems confusing the issue.
okay Thanks!
The issue got fixed, now I can see my logs.
The problem was, VS code was not running as administrator , so its not reflecting changes in designer and client.
I just tried to run it as administrator and it worked.