1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5library fuchsia.logger;
6
7using zx;
8
9enum LogLevelFilter : int8 {
10    NONE = -1;
11    INFO = 0;
12    WARN = 1;
13    ERROR = 2;
14    FATAL = 3;
15};
16
17// Max tags that can be passed to filter by listener.
18const uint8 MAX_TAGS = 5;
19
20// Max tag length that can be passed to filter by listener.
21const uint8 MAX_TAG_LEN_BYTES = 63;
22
23struct LogFilterOptions {
24    bool filter_by_pid;
25    uint64 pid;
26
27    bool filter_by_tid;
28    uint64 tid;
29
30    // If more than zero, logs would be filtered based on verbosity and
31    // |min_severity| would be ignored.
32    uint8 verbosity;
33
34    LogLevelFilter min_severity;
35
36    // If non-empty, return all messages which contain at least one specified
37    // tag.  If empty, messages will not be filtered by tag.
38    // Passed tags should not be more than |MAX_TAG_LEN_BYTES| bytes in length
39    // and max tags can be |MAX_TAGS|.
40    // Listener would be discarded if the limit is not followed.
41    vector<string>:MAX_TAGS tags;
42};
43
44// Max tags that will be attached to a LogMessage.
45const uint8 MAX_TAGS_PER_LOG_MESSAGE = 5;
46
47struct LogMessage {
48    uint64 pid;
49    uint64 tid;
50    // Nanoseconds since the system was powered on, aka ZX_CLOCK_MONOTONIC.
51    // https://fuchsia.googlesource.com/zircon/+/master/docs/syscalls/clock_get.md#supported-clock-ids
52    zx.time time;
53    int32 severity;
54
55    // See //zircon/system/ulib/syslog/include/syslog/wire_format.h. As messages
56    // can be served out of order, this should only be logged if more than last
57    // count.
58    uint32 dropped_logs;
59    vector<string>:MAX_TAGS_PER_LOG_MESSAGE tags;
60    string msg;
61};
62
63// Interface for LogListener to register to listen to logs.
64[Discoverable]
65interface Log {
66    // Listens to new log entries by calling Log() on |log_listener|.
67    // A null |options| indicates no filtering is requested.
68    1: Listen(LogListener log_listener, LogFilterOptions? options);
69
70    // Dumps all cached logs by calling LogMany() followed by Done() on
71    // |log_listener|.
72    // A null |options| indicates no filtering is requested.
73    2: DumpLogs(LogListener log_listener, LogFilterOptions? options);
74};
75
76// Interface to get and listen to socket from syslogger
77[Discoverable]
78interface LogSink {
79    // Client connects to send logs over socket
80    1: Connect(handle<socket> socket);
81};
82
83const uint64 MAX_LOG_MANY_SIZE_BYTES = 16384;
84
85interface LogListener {
86    // Called for single messages.
87    1: Log(LogMessage log);
88
89    // Called when |Log| service is serving cached logs.
90    // Max logs size per call is |MAX_LOG_MANY_SIZE_BYTES| bytes.
91    2: LogMany(vector<LogMessage> log);
92
93    // Called in the case |DumpLogs()| function of |Log| service was called and
94    // all cached logs have been dispatched to this listener.
95    3: Done();
96};
97