| 1 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | |
| 3 | """ |
| 4 | Syslog built-in backend. |
| 5 | """ |
| 6 | |
| 7 | __author__ = "Paul Durrant <paul.durrant@citrix.com>" |
| 8 | __copyright__ = "Copyright 2016, Citrix Systems Inc." |
| 9 | __license__ = "GPL version 2 or (at your option) any later version" |
| 10 | |
| 11 | __maintainer__ = "Stefan Hajnoczi" |
| 12 | __email__ = "stefanha@redhat.com" |
| 13 | |
| 14 | |
| 15 | from tracetool import out, expand_format_string |
| 16 | |
| 17 | |
| 18 | PUBLIC = True |
| 19 | CHECK_TRACE_EVENT_GET_STATE = True |
| 20 | |
| 21 | |
| 22 | def generate_h_begin(events, group): |
| 23 | out('#include <syslog.h>', |
| 24 | '') |
| 25 | |
| 26 | |
| 27 | def generate_h(event, group): |
| 28 | argnames = ", ".join(event.args.names()) |
| 29 | if len(event.args) > 0: |
| 30 | argnames = ", " + argnames |
| 31 | |
| 32 | out('#line %(event_lineno)d "%(event_filename)s"', |
| 33 | ' syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);', |
| 34 | '#line %(out_next_lineno)d "%(out_filename)s"', |
| 35 | event_lineno=event.lineno, |
| 36 | event_filename=event.filename, |
| 37 | name=event.name, |
| 38 | fmt=event.fmt.rstrip("\n"), |
| 39 | argnames=argnames) |
| 40 | |
| 41 | def generate_rs(event, group): |
| 42 | out(' let format_string = c"%(fmt)s";', |
| 43 | ' unsafe {::trace::syslog(::trace::LOG_INFO, format_string.as_ptr() as *const c_char, %(args)s);}', |
| 44 | fmt=expand_format_string(event.fmt), |
| 45 | args=event.args.rust_call_varargs()) |
| 46 | |
| 47 | def generate_h_backend_dstate(event, group): |
| 48 | out(' trace_event_get_state_dynamic_by_id(%(event_id)s) || \\', |
| 49 | event_id="TRACE_" + event.name.upper()) |