This file describes the public API of log sink server.
As said in the README, the API is built on top of asynconnection protocol, a call-return/message protocol over tls.
This API is used to send logs to this service.
Send a log in a fire-and-forget fashion. logData
is an object with the following fields:
date
: date
When the log was generated. Note that this is not an optional field, since the server can't assume the log was generated when it receives it.name
: string
The log "class". May be an endpoint url, function name, file name or anything that identifies this log inside the source applicationlevel
: uint
Recommended values: 0=debug, 1=info, 2=warn, 3=error, 4=fatal. But other values can also be usedrelevance
: uint
Must be one of: 0=bellow normal, 1=normal, 2=above normaltime
: optional uint
Any time related to this log, may be the endpoint response time, function execution time, etcmessage
: optional string
A log message, e.g. the error descriptioncommit
: optional Buffer
The revision name (in octets), e.g. in git this has 20 bytes (SHA1 output)extra
: optional json
Any JSON-compatible data (number, string, boolean, null, array or object)
logData
is an object with the exact same fields as described above. The only difference between this call and the message is the call receives the feedback about the operation result.
For example, if an application sends a log with a missing required field (like date) via message (the method above), it will be silently ignored. Using the call (this method), it will get an error back.
For performance, use the message method. For debug, use the call method.
Note that either method (message or call) will have the exactly same result. The server will not try harder to save a log sent by a call. So if you won't do nothing useful with an error response, don't use the call method (for performance sake).
This is the HTTPS endpoint. As discussed in the README, this alternative API over HTTPS is offered to allow a wider range of producers to send data to log sink. Note that the server binds to another port (as set in config.js
) for this API.
Using the API over asynconnection (described above) is better for performance and throughput.
The user/password credentials must be informed using HTTP's basic authentication.
The payload must be JSON-encoded and the Content-Type
header must be set to application/json
.
The payload is an object with the same keys as listed above. The only differences are:
- the
date
field is a string representation of the date, as defined by 'Combined date and time' ISO-8601, like:'2015-01-04T10:29:40.949Z'
- the
commit
field is a string with the data hex-encoded, like:'069276428dc4594f82d298aa0c3ddbebc93f7928'
.
The endpoint response will be a JSON formatted object with the keys:
ok
: boolean
Whether the log was inserted or noterror
: optional string
Ifok
is false, this will tell what have happened
This API streams live log data from producers to consumers and allows filtering the log that will be streamed.
Create a new log stream. options
is an object with the following fields:
id
: string
A name to give to this stream. This id will be used to shutdown the stream, for exampleincludeExtra
: boolean
If you are interested in theextra
field, set this totrue
. Otherwise, keep itfalse
to reduce network usage and latencyfilter
: Object
Let's the application declare which logs it wants to receive. An object with:origin
: string
The producer's user name. This is the only required field. You must have read access to logs from that user. You can always read your own data.name
: optional string
An exact match for the log namenameRegex
: optional regex
A regex to match against the log name (ignored ifname
is present)level
: optional Range
A range (see bellow) for the log levelrelevance
: optional Range
A range (see bellow) for the log relevancetime
: optional Range
A range (see bellow) for the log time fieldmessage
: optional string
An exact match for the log messagemessageRegex
: optional regex
A regex to match against the log message (ignored ifmessage
is present)commit
: optional Buffer
An exact match for the log commit field
Range
is an object with two optional keys with numeric (uint) value: min
and max
. Both ends are inclusive, that is 17
fits {min:17,max:17}
If the stream is created successfully, the server will start sending stream
(server-message:1) to the application (see bellow)
Shutdown the stream (given its id as string). The returned boolean tells whether the stream was active.
Shutdown all streams set by this connection. Streams created by other connections, even those under the same user/password, are not affected. There is no need to call this before closing the connection, the server will shutdown the streams by itself. In fact, this call is near useless.
After a stream is set, the server will send these messages to the application.
data
is an object with:
id
: string
The stream 'name'includeExtra
: boolean
Whether the stream was set to include theextra
field in the logslog
: Objectorigin
: stringdate
: datename
: stringlevel
: uintrelevance
: uinttime
: optional uintmessage
: optional stringcommit
: optional Bufferextra
: optional json
Only present if the original log has this field andincludeExtra
is true
The query API is used to query old log data
options
is an object with:
includeExtra
: booleanlimit
: uint
At most, how many logs to returnskip
: optional uint
How much logs to skip. This is used to provide paginated resultssort
: optional string The order used to return the logs. This is expressed as a space-separated string of field names. For example:'time -message extra.myOwnField'
means order bytime
asc, thenmessage
desc thenextra.myOwnField
asc. The default is'date'
(asc date)query
: Objectorigin
: stringdate
: Objectmin
: datemax
: optional date
relevance
: uintname
: optional stringnameRegex
: optional regexlevel
: optional Rangetime
: optional Rangemessage
: optional stringmessageRegex
: optional regexcommit
: optional Bufferextra
: optional json
Note that options.query
is very similiar to a stream filter, but with some important differences:
- a start date must be informed in
date.min
- exactly one value must be queried for
relevance
, since logs with different relevances are not stored together - the
extra
can also be queried. See the official docs for more on the syntax
This call returns an array of logs, each element is an object with:
origin
: stringdate
: datename
: stringlevel
: uintrelevance
: uinttime
: optional uintmessage
: optional stringcommit
: optional Bufferextra
: optional json
The meta API is used to get data about log sink service itself
Ask about the permissions the current user has. permissions
is an array of strings. The user name will be included in the answer and will always be the first element of the array.