Coder Social home page Coder Social logo

koa-logger-sls's Introduction

KOA-LOGGER-SLS

koa 的阿里云日志服务中间件

安装

$ npm i koa-logger-sls

配置 KOA 中间价

const logger from 'koa-logger-sls';
const app = new Koa();

const config = {
  customLoggerName: '自定义log调用名称,默认slsLogger'
  flushInterval: 1000,
  maxBufferLength: 1000,
  topic: 'your-topic-name',
  accessKeyId: '在阿里云sls申请的 accessKeyId',
  secretAccessKey: '在阿里云sls申请的 secretAccessKey',
  // 根据你的 sls project所在地区选择填入
  // 北京:http://cn-beijing.sls.aliyuncs.com
  // 杭州:http://cn-hangzhou.sls.aliyuncs.com
  // 青岛:http://cn-qingdao.sls.aliyuncs.com
  // 深圳:http://cn-shenzhen.sls.aliyuncs.com

  // 注意:如果你是在 ECS 上连接 SLS,可以使用内网地址,速度快,没有带宽限制。
  // 北京:cn-hangzhou-intranet.sls.aliyuncs.com
  // 杭州:cn-beijing-intranet.sls.aliyuncs.com
  // 青岛:cn-qingdao-intranet.sls.aliyuncs.com
  // 深圳:cn-shenzhen-intranet.sls.aliyuncs.com
  endpoint: 'your-endpoint',
  //目前支持最新的 api 版本, 不需要修改
  apiVersion: '2015-06-01',
  project: 'your-project-name',
  logStore: 'your-logStore-name'
}

app.use(logger(config));

打印日志

在任何可以拿到 ctx 的地方,使用 ctx.slsLogger 或者 ctx.customLoggerName

ctx.slsLogger.debug(anyMsg)
ctx.slsLogger.info(anyMsg)
ctx.slsLogger.warn(anyMsg)
ctx.slsLogger.error(anyMsg)

License

MIT

koa-logger-sls's People

Watchers

ethan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.