1.0.10 • Published 4 years ago

ali-sls-logger v1.0.10

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

Logger for Aliyun SLS

Fork form sls-logger Just change the way of import protobuf file from sls.proto to sls.json, so that it works well with webpack

Travis CI Build Status NPM Version NPM Downloads Dependency Status

The nodejs logger for aliyun SLS with minimum dependencies.

Configuration

Config NameDefaultTypeRequiredDescription
accessKeystringtrueYour access key to SLS
accessSecretstringtrueYour secret to access SLS
endpointstringtrueYour SLS endpoint, e.g. example.cn-hangzhou.log.aliyuncs.com
logstorestringtrueYour logstore name
sourcestringfalseSource for your logs
topicstringfalseTopic for your logs
hashkeystringfalse
compressfalsebooleanfalseUse lz4 to compress log payload
tagskey-value pairfalseExtra tags for your logs
levelINFOstring / numberfalseLog level
disabledfalsebooleanfalseDisable sls and log to stdout

Note: if your configuration is incorrect(fail to get logstore), all logs will be written to stdout.

Usage

const logger = new SlsLogger({
  endpoint: "example.cn-hangzhou.log.aliyuncs.com",
  accessKey: "your_access_key",
  accessSecret: "your_access_secret",
  logstore: "your_logstore",
  source: "test",
  topic: "test",
  compress: true,
  level: "INFO",
  disabled: true,
});

logger.info(
  "Hello world!",
  new Date(),
  function () { "abc"; },
  { a: 1, b: { c: 1 }, d: "123", e: false },
  new Object(),
  [1, 2, 3, "abc", false, null, undefined, new Error("error1")],
  SlsLogger.createField("module", "main"),
  1234,
  true,
  null,
  undefined,
  new Error("error2")
);

And you can pass a function as log message generator to improve performance; it will not be called unless the log level is enabled.

logger.debug(
  () => "Debug message from generator.",
  SlsLogger.createField("module", "debug")
);
// Set log level on the fly, e.g. through user signal or rest api.
logger.setLevel("DEBUG");

Contributing

This project welcomes contributions from the community. Contributions are accepted using GitHub pull requests. If you're not familiar with making GitHub pull requests, please refer to the GitHub documentation "Creating a pull request".

1.0.10

4 years ago

1.0.9

4 years ago