utils/log
Tag 4
Logging Service
  Published by utils on Tuesday, May 30th, 2017, 11:29:15 PM
  # StdLib Logging This is a simple logging service to provide a logging layer for services that you build on top of StdLib. The service gives you the ability to store logs, warnings and errors to up to 10,000 lines per service. ## Usage You can use the `log`, `warn` and `error` methods to for logging and the `read` comment to read them. You **must** be authenticated with a StdLib Library Token to use this service. You can do that by initializing `lib` like this: ```javascript // Retrieve your Library Token on the StdLib Dashboard const lib = require('lib')({ token: STDLIB_LIBRARY_TOKEN }); ``` You can create tokens in your [dashboard](https://dashboard.stdlib.com/dashboard). You also **must** pass in your service name. This can be done by initializing the `utils` service: ```javascript const utils = lib.utils({ service: 'service-name' }); ``` ### utils.log ```javascript utils.log("log message", { accepts: 'objects' }, (err) => { // Handle error }); ``` ### utils.log.error ```javascript utils.log.error("error message", new Error("Accepts error objects"), (err) => { // Handle error }); ``` ### utils.log.warn ```javascript utils.log.warn("warning message", { accepts: 'an object, too' }, (err) => { // Handle error }); ``` ### utils.log.read You can use this function to read the logs of your services. | Param | Description | | ----- | ----------- | | serviceName | Required: service name | | num | Optional: number of lines to return. Default is 100. | | json | Optional: whether to return the results in JSON format. Default is false. | ```bash # -t has to be passed with your library token lib utils.log.read -t STDLIB_LIBRARY_TOKEN --serviceName service-name ```
# StdLib Logging This is a simple logging service to provide a logging layer for services that you build on top of StdLib. The service gives you the ability to store logs, warnings and errors to up to 10,000 lines per service. ## Usage You can use the `log`, `warn` and `error` methods to for logging and the `read` comment to read them. You **must** be authenticated with a StdLib Library Token to use this service. You can do that by initializing `lib` like this: ```javascript // Retrieve your Library Token on the StdLib Dashboard const lib = require('lib')({ token: STDLIB_LIBRARY_TOKEN }); ``` You can create tokens in your [dashboard](https://dashboard.stdlib.com/dashboard). You also **must** pass in your service name. This can be done by initializing the `utils` service: ```javascript const utils = lib.utils({ service: 'service-name' }); ``` ### utils.log ```javascript utils.log("log message", { accepts: 'objects' }, (err) => { // Handle error }); ``` ### utils.log.error ```javascript utils.log.error("error message", new Error("Accepts error objects"), (err) => { // Handle error }); ``` ### utils.log.warn ```javascript utils.log.warn("warning message", { accepts: 'an object, too' }, (err) => { // Handle error }); ``` ### utils.log.read You can use this function to read the logs of your services. | Param | Description | | ----- | ----------- | | serviceName | Required: service name | | num | Optional: number of lines to return. Default is 100. | | json | Optional: whether to return the results in JSON format. Default is false. | ```bash # -t has to be passed with your library token lib utils.log.read -t STDLIB_LIBRARY_TOKEN --serviceName service-name ```
  info
context
enabled
bg
info
  parameters (click to modify)
{string}
message
(required)
Log message
{object}
data
= {}
extra data to store
  code
  info
context
enabled
bg
info
  parameters (click to modify)
{string}
message
(required)
Error message
{object}
data
= {}
error / extra data to store
  code
  info
context
enabled
bg
info
  parameters (click to modify)
{string}
message
(required)
Log message
{object}
data
= {}
extra data to store
  code
  info
context
enabled
bg
info
  parameters (click to modify)
{number}
num
= 100
(no description)
{boolean}
json
= false
(no description)
{any}
serviceName
(required)
(no description)
  code
  info
context
enabled
bg
info
  parameters (click to modify)
{string}
message
(required)
Warning message
{object}
data
= {}
extra data to store
  code