All Projects → stagnationlab → slack-logger

stagnationlab / slack-logger

Licence: MIT license
Slack logger that sends pretty formatted messages to a Slack channel.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to slack-logger

ELog
ELog----日志打印工具,带定位功能
Stars: ✭ 17 (+13.33%)
Mutual labels:  log
aixlog
Header-only C++ logging library
Stars: ✭ 95 (+533.33%)
Mutual labels:  log
vcore
Common, utility packages for Go
Stars: ✭ 16 (+6.67%)
Mutual labels:  log
guzzle-log-middleware
A Guzzle middleware to log request and responses automatically
Stars: ✭ 61 (+306.67%)
Mutual labels:  log
log
PSR-3 compatible logger
Stars: ✭ 32 (+113.33%)
Mutual labels:  log
magento2-inventory-log
Magento 2 - Inventory Log by KiwiCommerce
Stars: ✭ 33 (+120%)
Mutual labels:  log
SpringBoot-Examples
Spring boot 2.X version tutorial,Integrate various middleware to facilitate quick reference and use
Stars: ✭ 23 (+53.33%)
Mutual labels:  log
Multiplatform-Log
Kotlin Multi Platform Logger, for android an ios : Logcat & print
Stars: ✭ 49 (+226.67%)
Mutual labels:  log
node-typescript-starter
REST API using Node with typescript, KOA framework. TypeORM for SQL. Middlewares JWT (auth), CORS, Winston Logger, Error, Response
Stars: ✭ 19 (+26.67%)
Mutual labels:  winston
botkit-heroku-redis-example
Tiny example of running botkit on Heroku with RedisCloud
Stars: ✭ 21 (+40%)
Mutual labels:  slackbot
log-utils
Basic logging utils: colors, symbols and timestamp.
Stars: ✭ 24 (+60%)
Mutual labels:  log
fridaybot
Slack bot for https://spb-frontend.slack.com
Stars: ✭ 29 (+93.33%)
Mutual labels:  slackbot
react-native-log-ios
React Native iOS standalone logger
Stars: ✭ 37 (+146.67%)
Mutual labels:  log
arXie-Bot
arXie is a Slack bot that browses and filters the arXiv repository for you
Stars: ✭ 29 (+93.33%)
Mutual labels:  slackbot
Mimir
📱 A simple & efficient iOS logging framework for high usage apps
Stars: ✭ 13 (-13.33%)
Mutual labels:  log
audit-log
📑 Create audit logs into the database for user behaviors, including a web UI to query logs.
Stars: ✭ 135 (+800%)
Mutual labels:  log
webpack-log
A logger for the Webpack ecosystem
Stars: ✭ 18 (+20%)
Mutual labels:  log
cakcuk
A Command Bot Interface builder, CLI-based to easily create your CLI commands for your Workspace
Stars: ✭ 13 (-13.33%)
Mutual labels:  slackbot
logwatch
日志采集工具
Stars: ✭ 22 (+46.67%)
Mutual labels:  log
Analogy.LogViewer
A customizable Log Viewer with ability to create custom providers. Can be used with C#, C++, Python, Java and others
Stars: ✭ 172 (+1046.67%)
Mutual labels:  log

Slack logger nodejs library

Travis Coverage Downloads Version License

Sends pretty formatted messages to a Slack channel.

Example

Installation

This package is distributed via npm

npm install slack-logger

Features

  • Logs messages to a Slack channel.
  • Configurable logging level.
  • Pretty prints additional information.
  • Support handling messages from the channel.
  • Has built-in message handler for setting logging level.
  • One can easily add custom message handlers for restarting the server, deploying a new version etc.
  • Provides optional console logger that outputs nicely formatted color-coded log info to console.
  • Can integrate with any logging solution.
  • Works great with Bunyan but not required.
  • Also plays nicely with Winston.
  • Written in TypeScript.
  • Includes 100% test coverage.

Using in your application

Recommended way of using logging and the slack logger in your application is by using the provided Logger class that's a simple abstraction on top of Bunyan for getting component-specific loggers. See the examples/4-example-logger.ts for details.

import logger from "./services/logger";

// use the logger.get(componentName, filename) in each file to log for a specific component
const log = logger.get("register", __filename);

// logging message and info separately is recommended as the info gets nicely formatted and message becomes searchable
log.info(
  {
    user: {
      name: "Jack Daniels",
      email: "[email protected]",
    },
  },
  "user was successfully registered",
);

Examples

Take a look at the examples folder. It shows how to use the library for custom manual integrations, using it with Bunyan and Winston and also using the provided Logger class that uses Bunyan.

The examples can be run with npm start. They use a .env file for configuration, a .env-example file is provided (just copy it to .env file and change accordingly). Alternatively is the configuration file does not exist, the npm start script will ask for the details in the console and generates the configuration file.

Adding custom message handlers

Responding to slack channel messages is as easy as registering a simple handler.

// example of adding a custom message handler
slackLog.addMessageHandler({
  getName: () => "restart",
  getDescription: () => "restarts the application",
  handleMessage: (_message, log) => {
    log.post("restarting the application..");

    restart(); // implement this in some way
  },
});

Using the console logger

An optional console logger for Bunyan is provided that outputs the same information formatted nicely for the console.

Console log

To use this, simply register instance of ConsoleLog as a Bunyan stream.

import { ConsoleLog } from "slack-logger";

// register the console logger
logger.addStream({
  name: "console",
  level: "info",
  type: "raw",
  stream: new ConsoleLog({
    basePath: path.join(__dirname, "..", ".."), // configure to point to the root of the project
  }),
});

Commands

  • npm start to run the examples (prompts for configuration and choice of example).
  • npm build to build the production version.
  • npm test to run tests without code coverage.
  • npm run coverage to run tests with code coverage.
  • npm run lint to lint the codebase.
  • npm run prettier to run prettier.
  • npm run audit to run all pre-commit checks (prettier, build, lint, test). Run this before pull requests.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].