阿里云 SLS Stream
阿里云 SLS PutLogs Stream
使用方法
- 直接使用
const AliyunSlsStream = require('aliyun-sls-stream')
const stream = new AliyunSlsStream({
accessKeyId: 'your_very_secured_access_key_id',
secretAccessKey: 'your_very_secured_secret_access_key',
endpoint: 'an_aliyun_endpoint_for_sls',
project: process.env.ALIYUN_PROJECT,
logStore: process.env.ALIYUN_LOG_STORE
})
stream.write('Hello from the other side')
stream.write({ foo: 'bar' })
- 通过
bunyan
使用
const bunyan = require('bunyan')
const AliyunSlsStream = require('aliyun-sls-stream')
const log = bunyan.createLogger({
name: 'foo',
streams: [{
type: 'raw',
stream: new AliyunSlsStream({
accessKeyId: 'your_very_secured_access_key_id',
secretAccessKey: 'your_very_secured_secret_access_key',
endpoint: 'an_aliyun_endpoint_for_sls',
project: process.env.ALIYUN_PROJECT,
logStore: process.env.ALIYUN_LOG_STORE
}),
reemitErrorEvents: true
}],
level: 'debug'
})
log.debug('foobar')
log.debug({ foo: 'bar' }, 'foobar')
log.debug({ foo: 'bar' }, 'foobar: %s', ['foo', 'bar'])