-
Notifications
You must be signed in to change notification settings - Fork 19
/
Logging.py
126 lines (103 loc) · 4.87 KB
/
Logging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# coding=utf-8
# =============================================================================
# Copyright © 2017 FLIR Integrated Imaging Solutions, Inc. All Rights Reserved.
#
# This software is the confidential and proprietary information of FLIR
# Integrated Imaging Solutions, Inc. ("Confidential Information"). You
# shall not disclose such Confidential Information and shall use it only in
# accordance with the terms of the license agreement you entered into
# with FLIR Integrated Imaging Solutions, Inc. (FLIR).
#
# FLIR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
# SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE, OR NON-INFRINGEMENT. FLIR SHALL NOT BE LIABLE FOR ANY DAMAGES
# SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
# THIS SOFTWARE OR ITS DERIVATIVES.
# =============================================================================
#
# Logging.py shows how to create a handler to access logging events.
# It relies on information provided in the Enumeration, Acquisition, and
# NodeMapInfo examples.
#
# It can also be helpful to familiarize yourself with the NodeMapCallback
# example, as nodemap callbacks follow the same general procedure as
# events, but with a few less steps.
#
# This example creates a user-defined class, LoggingEventHandler, that inherits
# from the Spinnaker class, LoggingEvent. The child class allows the user to
# define any properties, parameters, and the event itself while LoggingEvent
# allows the child class to appropriately interface with the Spinnaker SDK.
import PySpin
# Define callback priority threshold; please see documentation for additional
# information on logging level philosophy.
LOGGING_LEVEL = PySpin.LOG_LEVEL_DEBUG # change to any LOG_LEVEL_* constant
class LoggingEventHandler(PySpin.LoggingEvent):
"""
Although logging events are just as flexible and extensible as other events,
they are generally only used for logging purposes, which is why a number of
helpful functions that provide logging information have been added. Generally,
if the purpose is not logging, one of the other event types is probably more
appropriate.
"""
def __init__(self):
super(LoggingEventHandler, self).__init__()
def OnLogEvent(self, logging_event_data):
"""
This function displays readily available logging information.
:param logging_event_data: Logging data.
:type logging_event_data: LoggingEventData
:rtype: None
"""
print "--------Log Event Received----------"
print "Category: %s" % logging_event_data.GetCategoryName()
print "Priority Value: %s" % logging_event_data.GetPriority()
print "Priority Name: %s" % logging_event_data.GetPriorityName()
print "Timestamp: %s" % logging_event_data.GetTimestamp()
print "NDC: %s" % logging_event_data.GetNDC()
print "Thread: %s" % logging_event_data.GetThreadName()
print "Message: %s" % logging_event_data.GetLogMessage()
print "------------------------------------\n"
def main():
"""
Example entry point; notice the volume of data that the logging event handler
prints out on debug despite the fact that very little really happens in this
example. Because of this, it may be better to have the logger set to lower
level in order to provide a more concise, focused log.
:rtype: None
"""
# Retrieve singleton reference to system object
system = PySpin.System.GetInstance()
# Create and register the logging event handler
#
# *** NOTES ***
# Logging events are registered to the system. Take note that a logging
# event handler is very verbose when the logging level is set to debug.
#
# *** LATER ***
# Logging events must be unregistered manually. This must be done prior to
# releasing the system and while the device events are still in scope.
logging_event_handler = LoggingEventHandler()
system.RegisterLoggingEvent(logging_event_handler)
# Set callback priority level
#
# *** NOTES ***
# Please see documentation for up-to-date information on the logging
# philosophies of the Spinnaker SDK.
system.SetLoggingEventPriorityLevel(LOGGING_LEVEL)
# Retrieve list of cameras from the system
cam_list = system.GetCameras()
num_cams = cam_list.GetSize()
print "Number of cameras detected: %i" % num_cams
# Clear camera list before releasing system
cam_list.Clear()
# Unregister logging event handler
#
# *** NOTES ***
# It is important to unregister all logging events from the system.
system.UnregisterLoggingEvent(logging_event_handler)
# Release system
system.ReleaseInstance()
raw_input("Done! Press Enter to exit...")
if __name__ == "__main__":
main()