1.0.12 • Published 2 years ago

sls-logger v1.0.12

Weekly downloads
3
License
MIT
Repository
github
Last release
2 years ago

Logger for Aliyun SLS

Node.js CI NPM Version NPM Downloads

The nodejs logger for aliyun SLS with minimum dependencies.

Configuration

Config NameDefaultTypeRequiredDescription
accessKeystringtrueYour access key to SLS
accessSecretstringtrueYour secret to access SLS
securityTokenstringfalseYour STS security token
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.12

2 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago