forked from vmware-archive/differential-datalog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.dl
More file actions
73 lines (70 loc) · 2.52 KB
/
log.dl
File metadata and controls
73 lines (70 loc) · 2.52 KB
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
/*
* Logging API.
*
* This API has two facets. First, it provides the `log()` function that can
* be invoked from a DDlog rule's Inspect operator to provide more visibility
* into the rule's evaluation. In addition to the usual log level and log
* message arguments, this function takes a `module` argument, which identifies
* the module or subsystem that this log message is associated with.
*
* Second, it provides a Rust configuration API that can only be invoked by the
* "host" program to set log level for individual modules and to supply a
* logging callback for each module (see `rust/template/types/log.rs`). This
* way, different modules can produce separate log streams or even use different
* logging mechanisms.
*
* NOTE: Internally, this library maintains a global module-to-log_callback
* map shared by all DDlog instances running in the same address space. The host
* program is responsible for maintaining this mapping via the Rust API in
* `log.rs`.
*
* Other related files:
* `log4j.dl` - specializes the logging API for using log4j loggers
* `ddlog_log.rs` - Rust logging API
* `ddlog_log.h` - matching C bindings
* `DDlogAPI.java (DDlogAPI.log_set_callback method)` - Java API to control
* logging.
*
* === Example ===
*
* In DDlog:
* ```
* // Declare module id's for logging purposes
* function mod_SPAN_UUID(): log.module_t = 100
*
* // Use log() function in a rule
* Span(entity, tn) :- Binding(entity, tn),
* Inspect log(mod_SPAN_UUID(), 5, "Span(entity,tn) :- Binding(.entity=${deref(entity)},.tn=${deref(tn)}))").
* ```
*
* In Java:
* ```
* // Module id declarations must match DDlog values:
* static int MOD_SPAN_UUID1 = 100;
* // Set logging callback and log level from Java
* DDlogAPI.log_set_callback(
* MOD_SPAN_UUID1,
* (msg, level) -> System.err.println("Log msg from module1 (" + level + "): " + msg),
* 5);
* ```
* ===============
*
*/
/* `module_t` type identifies the subsystem or component for logging purposes.
*/
typedef module_t = signed<32>
typedef log_level_t = signed<32>
/*
* Write to a log stream
*
* `module` - Identifies the subsystem writing to the log. A log record is only
* produced if logging has been enabled for this subsystem (see
* `log.rs`)
* `level` - log level
* `msg` - error message (UTF-8)
*
* This function returns a `()` so that it can be used as part of an expression
* of an Inspect operator.
*/
#[has_side_effects]
extern function log(module: module_t, level: log_level_t, msg: string)