Log

Log provides basic isomorphic logging capability that can log to all of the server console, the client console, and/or to a database log.

The log levels are:

NameCodeMethod
traceTtrace
logLlog
infoIinfo
warnWwarn
errorEerror
fatalFerror
neverN

Tyr.config() takes the following log level options:

OptionDefaultNotes
logLevel'info'Sets the default logging threshold.
clientLogLevellogLevel || 'error'A log's level must be >= this to be logged to the client console.
consoleLogLevellogLevel || 'info'A log's level must be >= this to be logged to the server console.
dbLogLevellogLevel || 'info'A log's level must be >= this to be logged to the database tyrLog collection.
trace|log|info|warn|error|fatal(opts): void

These are the basic logging methods. These are all available directly on Tyr as well.

opts is a list of the following:

OptionNotes
stringThe log message.
ErrorAn Error or its subclasses. The stack trace will be logged as well. The log message will default to this unless a message is provided directly.
objectAn object which can contain any of the fields in the Log collection.

Tyranid will automatically log the timestamp, details about the request (method, path, query string, duration, user agent, ...), and so on.

Examples:

Tyr.info('a test message')
Tyr.warn('a log message', { e: 'http' });
Tyr.warn({ e: 'http', m: 'a log message' });
Tyr.fatal({ e: 'http', m: 'a log message' }, new Error())

Use Log.mixin() to add custom Log fields that you would like to record.

For example, say you wanted to store a "zone" property on log messages that was a link to a "Zone" collection:

Tyr.Log.mixin({
  fields: {
    zone: { link: 'zone' }
  }
});

You could then make log() calls referencing the new property:

Tyr.log({ m: 'my log message', zone: myZone })
addEvent(name, label, notes): void

This allows you to define additional event types for log messages so that you can categorize them.

Tyranid provides the following default event types:

NameLabelNotes
httpHTTPHTTP Requests
dbDatabaseDatabase Requests
historicalHistoricalHistorical diagnostics
subscriptionSubscriptionsSubscription diagnostics