See the PyUAF HTML documentation for more info. """ import time, os import pyuaf from pyuaf.client import Client from pyuaf.client.settings import ClientSettings from pyuaf.util import loglevels, Address, NodeId # we can create some ClientSettings: settings = ClientSettings() settings.applicationName = "MyClient" settings.discoveryUrls.append("opc.tcp://localhost:4841") settings.logToStdOutLevel = loglevels.Info # print Info, Warning and Error logging to the console settings.logToCallbackLevel = loglevels.Debug # send Debug, Info, Warning and Error logging to the callback # And if you want to catch the logging output, you may also define a callback. # In this case we define a callback to write the logging output to a file in the user's home directory. # (but this callback is optional of course, only define one if you want to do something more with the # logging output than simply printing it to the console (i.e. sending it to the stdout)) f = open(os.path.expanduser("~/my_logging_output.txt"), "w") def callback(msg): logDetailsString = "" logDetailsString += time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(msg.ctime)) logDetailsString += ".%.3d " % msg.msec logDetailsString += "%-10s " % msg.applicationName logDetailsString += "%-20s " % msg.loggerName
See the HTML documentation of PyUAF for more info! """ import pyuaf from pyuaf.util import loglevels from pyuaf.client import Client from pyuaf.client.settings import ClientSettings from pyuaf.util import Address, NodeId # create a client that # - logs everything to the standard out ("stdout", i.e. the Windows DOS Prompt or the Linux shell) # - only logs warnings and errors to an external callback function settings = ClientSettings() settings.discoveryUrls.append("opc.tcp://localhost:4841") settings.applicationName = "myClient" settings.logToStdOutLevel = loglevels.Debug settings.logToCallbackLevel = loglevels.Error # define the callback for the logging def myLoggingCallback(msg): print("************ CALLBACK SAYS: ************") if msg.level == loglevels.Error: print("Error message received: %s" %str(msg)) elif msg.level == loglevels.Warning: print("Warning message received: %s" %str(msg)) else: print("Info or debug message received: %s" %str(msg)) # create the client myClient = Client(settings, myLoggingCallback) # try to read the Value attribute of some non-existing node (so errors will be sent to the callback)
See the PyUAF HTML documentation for more info. """ import time, os import pyuaf from pyuaf.client import Client from pyuaf.client.settings import ClientSettings from pyuaf.util import loglevels, Address, NodeId # we can create some ClientSettings: settings = ClientSettings() settings.applicationName = "MyClient" settings.discoveryUrls.append("opc.tcp://localhost:4841") settings.logToStdOutLevel = loglevels.Info # print Info, Warning and Error logging to the console settings.logToCallbackLevel = loglevels.Debug # send Debug, Info, Warning and Error logging to the callback # And if you want to catch the logging output, you may also define a callback. # In this case we define a callback to write the logging output to a file in the user's home directory. # (but this callback is optional of course, only define one if you want to do something more with the # logging output than simply printing it to the console (i.e. sending it to the stdout)) f = open(os.path.expanduser("~/my_logging_output.txt"), "w") def callback(msg): logDetailsString = "" logDetailsString += time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(msg.ctime)) logDetailsString += ".%.3d " %msg.msec logDetailsString += "%-10s " %msg.applicationName logDetailsString += "%-20s " %msg.loggerName logDetailsString += "%-8s " %loglevels.toString(msg.level) # msg.message may contain multiple lines, so we prepend the other logging details in # front of each line:
See the HTML documentation of PyUAF for more info! """ import pyuaf from pyuaf.util import loglevels from pyuaf.client import Client from pyuaf.client.settings import ClientSettings from pyuaf.util import Address, NodeId # create a client that # - logs everything to the standard out ("stdout", i.e. the Windows DOS Prompt or the Linux shell) # - only logs warnings and errors to an external callback function settings = ClientSettings() settings.discoveryUrls.append("opc.tcp://localhost:4841") settings.applicationName = "myClient" settings.logToStdOutLevel = loglevels.Debug settings.logToCallbackLevel = loglevels.Error # define the callback for the logging def myLoggingCallback(msg): print("************ CALLBACK SAYS: ************") if msg.level == loglevels.Error: print("Error message received: %s" % str(msg)) elif msg.level == loglevels.Warning: print("Warning message received: %s" % str(msg)) else: print("Info or debug message received: %s" % str(msg)) # create the client myClient = Client(settings, myLoggingCallback)