cycle-log-driver

0.1.3 • Public • Published

cycle-log-driver

CircleCI

Logging driver for CycleJS that enables simple client-side log.

Usage

npm install --save cycle-log-driver

Big picture, the log driver consumes a stream of shapes {name, (message|messages), color?}, and creates a nice log in the console to review those items after they've passed through the stream. The log driver creation function also takes a configuration for log output to include, making it much easier to change logging depending on the environment (for instance, not logging in production).

import {run} from '@cycle/run'
import makeLogDriver from 'cycle-log-driver'

function main(sources) {
	return {
		// other stuff...,
		log: xs.merge(
			props_.map(props => ({name: `state`, message: props, color: `#4286f4`})),
			event_.map(event => ({name: `action`, message: event, color: `#4cc456`})),
			request_.map(({url, method}) => ({
				name: `request`,
				message: `${method} ${url}`,
				color: `#cca23b`,
			})),
			sources.http.select().flatten().map(({request, status, body}) => ({
				name: `response`,
				messages: [`${request.method} ${request.url}`, status, body],
				color: `#f94f31`,
			}))
		),
	}
}

run(main, {
	// other stuff...,
	log: makeLogDriver({include: [`state`, `action`, `request`, `response`]}),
})

Package Sidebar

Install

npm i cycle-log-driver

Weekly Downloads

8

Version

0.1.3

License

MIT

Unpacked Size

6.27 kB

Total Files

5

Last publish

Collaborators

  • tshelburne