npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@churchill/core

v1.0.0

Published

Churchill logger core functionality

Readme

Churchill Core

Churchill core is the actuall logger. By default we include @churchill/console as the default transport, but you might want to install additional transports like file, elastic, http or socket.

Installation

npm install @churchill/core
# or if you want to log to different transport then the default
npm install @churchill/core @churchill/console
npm install @churchill/core @churchill/file
npm install @churchill/core @churchill/elastic @elastic/elasticsearch
# ...

Setup

Setting up Churchill is easy. Simply call churchill with a list of transports and if you are happy with the default formatting, you can use the logger in your services.

// logger.js
const churchill = require("@churchill/core");
const Console = require("@churchill/console");
const File = require("@churchill/file");

const createNamespace = churchill({
  transports: [
    Console.create(),
    File.create({ filename: "error.log", maxLevel: "error" }),
    File.create({ filename: "combined.log" })
  ]
});

Here is an example service:

// worker-a.js
const logger = require('./logger')('worker:a')
logger.error('Got an error!', new Error('Err!'))
logger.warn('Ups?')
logger.info('Log me with some data!', { here: { are: 'some metadata' }})
// the default max log level is info (anything below will not be logged by default)
logger.verbose('Hello!')
logger.debug( ... )
logger.silly( ... )

The default log levels contains 6 levels, that are ascending numerical values, where the lower the number the more important the log message is.

const LEVELS = {
  error: 0,
  warn: 1,
  info: 2, // Default maximum log level
  verbose: 3,
  debug: 4,
  silly: 5
};

Transports

This is the list of currently supported transports. Check the examples folder to see their usage. (Note that all transports are exported under churchill.trasports.<Transport>)

| Name | Description | Example | | --------------------- | ----------------------------------------- | ----------------------------------------------------------------------- | | Console | Log to console | Console.create({ errorLevel: "error", ... }) | | File | Log to a file | File.create({ filename: "error.log", level: "error", ... }) | | Stream | Log to any arbitrary stream. | Stream.create({ stream: <Stream>, ... }) | | HTTP | Log to a HTTP stream. | HTTP.create({ path: "https://domain.com/path", ... }) | | Elastic | Log to an elasticsearch index. | Elastic.create({ node: "http://localhost:9200", index: "logs", ... }) | | Socket* | (*Not Implemented Yet) Log to a socket | Socket.create({ host: "127.0.0.1", port: 1337, ... }) |

Customization

Custom Log Levels

You can also specify custom levels.

const customLevels = {
  critical: 0,
  warning: 1,
  log: 2,
  debug: 3
};

const customColors = {
  critical: "red",
  warning: "orange",
  log: "blue",
  debug: "gray"
};

churchill({ levels: customLevels, colors: customColors });

Available colors are black, red, green, yellow, blue, magenta, cyan, white, gray, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright. For more information check the chalk package.

Custom Formats

Churchill supports custom formatting functions. A formatting function accepts info (global format) or info, output, logger (transport format) objects which is the logged message, globally formatted message and the logger instance. The return value is what will be sent to transport streams.

const util = require("util");

const customGlobalFormat = info => {
  return { ...info, logger: "churchill:" };
};

const customFormat = info => {
  const { logger, namespace, timestamp, level, ms, args } = info;

  return `${logger}${namespace} ${level} ${args.map(arg => util.format(arg)).join(" ")} +${ms}ms`;
};

const createLogger = churchill({
  format: customGlobalFormat,
  transports: [Console.create({ format: customFormat })]
});

const loggerA = createLogger("worker:a");
const loggerB = createLogger("worker:b");
const loggerC = createLogger("worker:c");

loggerA.info("test", { metadata: "some info" });
// churchill:worker:a info test { metadata: 'some info' } +1ms
loggerB.info("test", { metadata: "some info" });
// churchill:worker:b info test { metadata: 'some info' } +0ms
loggerC.error("test", { metadata: "some info" });
// churchill:worker:c error test { metadata: 'some info' } +0ms

Custom transport

For implementing custom transport please see transport package.

Environmental Variables

You can change the funcionality of the logger by setting enviromental variables.

| Variable | Description | | ----------------------- | -------------------------------------------------------------------------------------------------- | | CHURCHILL_DEBUG | List of enabled namespaces separated by a comma, can be also used with wildcard (i.e. worker:a*) | | CHURCHILL_DEBUG_LEVEL | Max. level to log (i.e. debug) |

Logging Uncaught Exceptions

Simply add listener for the uncaughtException and log whatever you need.

process.on("uncaughtException", err => {
  logger.error(err);
  // Note: if you use any asynchronous transport, you will need to wait till it is written before exiting the program
});

Contributors

Help us improve and be recognised!

| Aleš Menzel💻 📖 | | :---: |

This project follows the all-contributors specification. Contributions of any kind are welcome!

License

This package is developed under the MIT licence.