Coder Social home page Coder Social logo

logboxslackappender's Introduction

logboxSlackAppender

LogBox Appender to send messages to Slack.

Property description

  • userToken (required) - Token of the User for Slack
  • channel (required) - channel name or ID
  • appURI - URI of slack API
  • postAsUser - whether to post as anonymous bot, or as the user from token
  • useThread - whether to thread the http request
  • useSeverity - whether to include emoji and colors based off logBox severity

Example logBox declaration in Coldbox.cfc

logBox = {
	// Define Appenders
	appenders = {
		coldboxTracer = { class="coldbox.system.logging.appenders.ColdboxTracerAppender" },
		slackLog = {
		 class="appenders.SlackAppender",
		 properties =
			{
			 channel="XXX",
			 userToken="XXX"
			}
		}
	},
	// Root Logger
	root = { levelmax="INFO", appenders="coldboxTracer" },
	// Granular Categories
	categories = {
		"slack" = {appenders="slackLog"}
	}
};

Simple usage in a handler

component extends="handlers.baseHandler" displayname="Foo" {
	property name="slackLogger" inject="logbox:logger:slack";

	public void function sendSlackMessage (event,rc,prc) {
		slackLogger.debug("Some Debug Data");
		event.renderData(data="Sent Message");
	}
}

Usage with overriding properties

Create an extraInfo struct with an overrideProperties struct that overrides the default properties

component extends="handlers.baseHandler" displayname="Foo" {
	property name="slackLogger" inject="logbox:logger:slack";
	var extraInfo = {
		overrideProperties = { //optional
			channel = "customChannel", //Dont use the channel that was defined when the logger was setup, use this one.
			postAsUser = false //Post as anonymous bot, not the user
		}
	}
	public void function sendSlackMessage (event,rc,prc) {
		slackLogger.info("Some informative info",extraInfo);
		event.renderData(data="Sent Message");
	}
}

Usage with attachments

Create an extraInfo struct with an attachments array defined by slack here: https://api.slack.com/docs/attachments

component extends="handlers.baseHandler" displayname="Foo" {
	property name="slackLogger" inject="logbox:logger:slack";
	var extraInfo = {
		attachments =  [
			{
			"fallback": "Required plain-text summary of the attachment.",
			"color": "##36a64f",
			"pretext": "Optional text that appears above the attachment block",
			"author_name": "Bobby Tables",
			"author_link": "http://flickr.com",
			"author_icon": "http://png-2.findicons.com/files/icons/1609/ose_png/256/warning.png",
			"title": "Slack API Documentation",
			"title_link": "https://api.slack.com/",
			"text": "Optional text that appears within the attachment",
			"fields": [
				{
					"title": "Text",
					"value": "Foo",
					"short": true
				},
				{
					"title": "Stuff",
					"value": "Bar",
					"short": true
				}
			],
			"image_url": "http://my-website.com/path/to/image.jpg"
			}
		]
	}
	public void function sendSlackMessage (event,rc,prc) {
		slackLogger.warn("Some warning info",extraInfo);
		event.renderData(data="Sent Message");
	}
}

logboxslackappender's People

Contributors

kennethwsmith avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

homestar9

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.