About logging to Shotgun via Shotgun API I will write about the case of intentionally leaving an arbitrary log instead of the log that is automatically left.
On Shotgun, the data table for logging is ** "EventLogEntry Entity" **. If someone does something on Shotgun Web (opening a page, changing status, browsing a version, etc.), it will be logged.
--Cannot be deleted --Uneditable --Recorded both from the browser and via the API
… Because it is a log, of course
The log is recorded without doing anything, In addition, there are times when you want to log your own events as some kind of landmark.
It's a so-called "custom event".
There is no method for recording the event, As usual, ** create ** on the EventLogEntry entity
By the way, speaking of "RTS" in the project column, It is serialized here> http://area.autodesk.jp/column/tutorial/road_to_stingray/ I also gave a lecture the other day> http://www.guncys.com/?p=378 I'm looking forward to the completion!
Since event_type itself is just a text field, you can write it freely, Basically, it is better to match the following format
{What is the log}_{Which entity to log to}_{What kind of operation did you do}
It is an underscore that connects "who", "where", and "what". Observing from the log written as standard, it feels like the upper camel case is connected with an underscore for 3 elements.
Based on the contents so far, the script that leaves an arbitrary log is as follows, for example.
python
data = {}
data['project'] = PROJ
data['event_type'] = 'MyApp_Entity_SomeAction'
data['description'] = 'some action'
data['user'] = SCRIPT_USER
data['entity'] = SOME_TARGET
sg.create('EventLogEntry',data)
The example sentence to get the written log looks like the following
python
eventType = 'MyApp_Entity_SomeAction'
log = sg.find_one(
'EventLogEntry',
[['event_type','is',eventType ],['project','is',PROJ]],
['created_at','entity'],
order=[{'field_name':'id','direction':'desc'}]
)
By using the find_one
method and specifying ʻorderto return in the newest order (where'desc') I have one "latest'Myscript_Shot_SomeAction'". Also, put
'created_at'` in the returned field to get the timestamp.
If you enter the event type, it would be nice to make it a function so that it will be returned.
--Use create. -** Be careful as it cannot be erased **!
Here are some examples of event types that will flow if you use them normally (= without doing anything like the above).
How to write event driven triggers https://support.shotgunsoftware.com/entries/44575-How-to-write-event-driven-triggers
Event Types https://github.com/shotgunsoftware/python-api/wiki/Event-Types
There is also such a good thing
Shotgun Event Framework https://github.com/shotgunsoftware/shotgunEvents
Recommended Posts