Class: Connection

Connection

new Connection()

Connection.js, line 55

Extends

  • EventEmitter

Members

nullablecommitBuffer

Default value for the commit field

LEVELnumber

Standard level values

Properties:
Name Type Default Description
DEBUG number 0
INFO number 1
WARN number 2
ERROR number 3
FATAL number 4

RELEVANCEnumber

Possible relevance values

Properties:
Name Type Default Description
LOW number 0
NORMAL number 1
HIGH number 2

Default value for relevance (initial value is NORMAL)

STATEnumber

Ready state values for Connection#state

Properties:
Name Type Default Description
UNINITIALIZED number 0
CONNECTING number 1
CONNECTED number 2
CLOSED number 4

readonlystateConnection#STATE

The connection readiness. If the connection is not ready yet, all commands will be buffered and executed when appropriate

readonlyuserstring

User name, set after Connection#connect() is called

Methods

bindName(name){Logger}

Connection.js, line 336

Use it to ease logging multiple times with the same name field. Logs created this way will have the time field set as the elapsed time (in ms) between this call and subsequent calls to Logger methods

Name Type Description
name string
Deprecated
Returns:
Type Description
Logger

close(callback)

Connection.js, line 171

Close the connection

Name Type Description
callback function optional

added as listener to Connection#event:close

connect(user, password, socketOptionsOrUrl)

Connection.js, line 142

Start the connection with the log sink server. To connect to a server using TLS, set socketOptions.secure as true

Name Type Description
user string

account name in the server

password string

base 64 encoded, like 'u4zJEF16B5UAvalmp+oY0QdSSvhqMBxj64WYlK7Omio='

socketOptionsOrUrl Object | string

In node: an object passed to net.connect or tls.connect, if socketOptions.secure is true. For browser: the websocket url as a string, like 'wss://example.com:8017/'

debug(name, message, extra)

Connection.js, line 269

Simpler way for Connection#sendLog with level set as DEBUG

Name Type Description
name string
message string | Error optional
extra * optional

any JSON-compatible value

disable()

Connection.js, line 193

Disables the connection, making it ignore all logs and always failing in stream() and query(). This is useful for a test environment, for example, because otherwise the internal buffer would grow unboundedly

error(name, message, extra)

Connection.js, line 299

Simpler way for Connection#sendLog with level set as ERROR

Name Type Description
name string
message string | Error optional
extra * optional

any JSON-compatible value

fatal(name, message, extra)

Connection.js, line 309

Simpler way for Connection#sendLog with level set as FATAL

Name Type Description
name string
message string | Error optional
extra * optional

any JSON-compatible value

getLogger(name, relevance, basicExtra){Logger}

Connection.js, line 324

Use it to ease logging multiple times with the same name, relevance and some extra keys Logs created this way will have the time field set as the elapsed time (in ms) between this call and subsequent calls to Logger methods. Keys on the basicExtra parameter will be assigned to the extra object passed when calling Logger methods.

Name Type Default Description
name string
relevance Connection#RELEVANCE Connection#relevance optional
basicExtra Object optional
Returns:
Type Description
Logger

getPermissions(callback)

Connection.js, line 426

Get the list of available permissions for the current user The current user name will be included in the answer and will always be the first element of the array

Name Type Description
callback function

cb(err,permissions)

info(name, message, extra)

Connection.js, line 279

Simpler way for Connection#sendLog with level set as INFO

Name Type Description
name string
message string | Error optional
extra * optional

any JSON-compatible value

query(query, options, callback)

Connection.js, line 396

Query log data

Name Type Default Description
query Object {} optional
Name Type Default Description
date Object optional
Name Type Default Description
min Date yesterday optional
max Date optional
origin string Connection#user optional
relevance Connection#RELEVANCE Connection#relevance optional
name string optional
nameRegex RegExp optional

ignored if query.name is given

level Connection~Range optional
time Connection~Range optional
message string optional
messageRegex RegExp optional

ignored if query.message is given

commit Buffer optional
extra * optional

follows mongodb query syntax, see official docs

options Object {} optional
Name Type Default Description
includeExtra boolean false optional

if false (default), the extra field is not received

limit number 100 optional
skip number 0 optional
sort string 'date' optional

same syntax as mongoose, example: 'date -time'

callback function

fn(err, logs:Array)

sendLog(data, callback)

Connection.js, line 216

The low level way to send log data to the server. Most of times, Connection#info (and its family) and Connection#bindName will be much more useful.

Name Type Description
data Object
Name Type Default Description
name string
level Connection#LEVEL
date Date new Date optional
relevance Connection#RELEVANCE Connection#relevance optional
commit Buffer Connection#commit optional
time number optional
message string optional
extra * optional

any JSON-compatible data (like number, string, boolean, null, array and object)

callback function optional

optional cb(err). If not present, the log is sent in a fire-and-forget fashion, provinding better latency and throughput

stream(filter, includeExtra, callback)

Connection.js, line 356

Create a log stream. This is done asynchronously: the stream will be passed to the callback

Name Type Default Description
filter Object {} optional

filter the stream

Name Type Default Description
origin string Connection#user optional

the user must have permission to read from it

name string optional
nameRegex RegExp optional

ignored if filter.name is given

level Connection~Range optional

see standard values in Connection#LEVEL

relevance Connection~Range optional

see possible values in Connection#RELEVANCCE

time Connection~Range optional
message string optional
messageRegex RegExp optional

ignored if filter.message is given

commit Buffer optional
includeExtra boolean false optional

if false (default), log's extra field won't be received, improving performance

callback function

cb(err, logStream:LogStream)

warn(name, message, extra)

Connection.js, line 289

Simpler way for Connection#sendLog with level set as WARN

Name Type Description
name string
message string | Error optional
extra * optional

any JSON-compatible value

Type Definitions

LogObject

Properties:
Name Type Argument Description
origin string
date Date
name string
level Connection#LEVEL
relevance Connection#RELEVANCE
time number <optional>
message string <optional>
commit Buffer <optional>
extra * <optional>

RangeObject

Properties:
Name Type Argument Description
min number <optional>

inclusive

max number <optional>

inclusive

Events

close

Connection.js, line 26

Emited when the connection is closed and no more activity will happen. Connection#state is CLOSED

connect

Connection.js, line 15

Fired when the connection is ready. Connection#state is CONNECTED

connecting

Connection.js, line 9

Fired when Connection#connect() is called. Connection#state is CONNECTING

error

Connection.js, line 21
Type:
  • Error