All Projects → bevry → Caterpillar

bevry / Caterpillar

Licence: other
Caterpillar is the ultimate logging system for Deno, Node.js, and Web Browsers. Log levels are implemented to the RFC standard. Log entries can be filtered and piped to various streams, including coloured output to the terminal, the browser's console, and debug files. You can even write your own transforms.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Caterpillar

Logbook
An extensible Java library for HTTP request and response logging
Stars: ✭ 822 (+149.09%)
Mutual labels:  logging, logger, client-side
Logcat
Android 日志打印框架,在手机上可以直接看到 Logcat 日志啦
Stars: ✭ 189 (-42.73%)
Mutual labels:  logging, logger
Acho
The Hackable Log
Stars: ✭ 189 (-42.73%)
Mutual labels:  logging, logger
Analog
PHP logging library that is highly extendable and simple to use.
Stars: ✭ 314 (-4.85%)
Mutual labels:  logging, logger
Wormholy
iOS network debugging, like a wizard 🧙‍♂️
Stars: ✭ 2,010 (+509.09%)
Mutual labels:  logging, logger
Android Plog
A Pure, Pretty and Powerful logging library for android.
Stars: ✭ 168 (-49.09%)
Mutual labels:  logging, logger
Timber Elixir
🌲 Great Elixir logging made easy
Stars: ✭ 226 (-31.52%)
Mutual labels:  logging, logger
Logdna Agent
LogDNA Agent streams from log files to your LogDNA account. Works with Linux, Windows, and macOS Servers
Stars: ✭ 134 (-59.39%)
Mutual labels:  logging, logger
Chipmunk
log analysis tool
Stars: ✭ 247 (-25.15%)
Mutual labels:  logging, logger
gxlog
A concise, functional, flexible and extensible logger for go.
Stars: ✭ 65 (-80.3%)
Mutual labels:  logger, logging
Pygogo
A Python logging library with superpowers
Stars: ✭ 265 (-19.7%)
Mutual labels:  logging, logger
Dotzu
📱👀 In-App iOS Debugging Tool With Enhanced Logging, Networking Info, Crash reporting And More.
Stars: ✭ 1,802 (+446.06%)
Mutual labels:  logging, logger
Quicklogger
Library for logging on files, console, memory, email, rest, eventlog, syslog, slack, telegram, redis, logstash, elasticsearch, influxdb, graylog, Sentry, Twilio, ide debug messages and throw events for Delphi/Firemonkey/freepascal/.NET (Windows/Linux/OSX/IOS/Android).
Stars: ✭ 137 (-58.48%)
Mutual labels:  logging, logger
Heliumlogger
A lightweight logging framework for Swift
Stars: ✭ 169 (-48.79%)
Mutual labels:  logging, logger
Monolog Cascade
Configure multiple loggers and handlers in the blink of an eye
Stars: ✭ 136 (-58.79%)
Mutual labels:  logging, logger
Monolog Bundle
Symfony Monolog Bundle
Stars: ✭ 2,532 (+667.27%)
Mutual labels:  logging, logger
Nestjs Pino
Platform agnostic logger for NestJS based on Pino with REQUEST CONTEXT IN EVERY LOG
Stars: ✭ 283 (-14.24%)
Mutual labels:  logging, logger
Android Remote Debugger
A library for remote logging, database debugging, shared preferences and network requests
Stars: ✭ 132 (-60%)
Mutual labels:  logging, logger
Structured Log
A JavaScript implementation of Serilog's hybrid text/structured logging
Stars: ✭ 133 (-59.7%)
Mutual labels:  logging, logger
Golog
A high-performant Logging Foundation for Go Applications. X3 faster than the rest leveled loggers.
Stars: ✭ 208 (-36.97%)
Mutual labels:  logging, logger

Caterpillar

Travis CI Build Status NPM version NPM downloads Dependency Status Dev Dependency Status
GitHub Sponsors donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

Caterpillar is the ultimate logging system for Deno, Node.js, and Web Browsers. Log levels are implemented to the RFC standard. Log entries can be filtered and piped to various streams, including coloured output to the terminal, the browser's console, and debug files. You can even write your own transforms.

Usage

Complete API Documentation.

Examples

Overview

The RFC Log Levels are provided by the rfc-log-levels package which follows RFC 3164 - The BSD Syslog Protocol.

Log Entries that are within the lineLevel range, will have their line information fetched using the get-current-line package.

The Logger is what you write your log messages to, which you then pipe to destinations and transforms.

The Filter transport is used to filter out log levels that we do not want to pass onto the next destination.

The Human transport is used to convert the Log Entries into a human readable and colourful output.

The Browser transport is used to send the human output, including colours, to the Web Browser console.

The Transform is used to write your own transforms, and is what all the others are based from.

Node.js Guide

To get started for Node.js, setup a new Node.js project for this guide and install Caterpillar.

mkdir caterpillar-guide
cd caterpillar-guide
npm init
npm install --save caterpillar
touch index.js

Then edit our index.js file with the following, that will output all the log messages in JSON format to stdout, and can be run via node index.js:

const { Logger } = require('caterpillar')
const logger = new Logger()

logger.pipe(process.stdout)

logger.log('warn', 'this is a warning, which is level', 4)
logger.warn('this is a warning, which is level', 4)
logger.log('debug', 'this is a debug message, which is level', 7)
logger.warn('this is a debug message, which is level', 7)

Outputting in JSON format is not a nice experience, instead we can do better by using the Human transport such that it is human readable.

const { Logger, Human } = require('caterpillar')
const logger = new Logger()

logger.pipe(new Human()).pipe(process.stdout)

logger.log('warn', 'this is a warning, which is level', 4)
logger.warn('this is a warning, which is level', 4)
logger.log('debug', 'this is a debug message, which is level', 7)
logger.warn('this is a debug message, which is level', 7)

However, perhaps we want to still store the JSON format for querying later. We can pipe the human format to stdout as before, but we can pipe the raw output to a debug file.

const { Logger, Human } = require('caterpillar')
const logger = new Logger()

const { createWriteStream } = require('fs')
logger.pipe(createWriteStream('./debug.log'))

logger.pipe(new Human()).pipe(process.stdout)

logger.log('warn', 'this is a warning, which is level', 4)
logger.warn('this is a warning, which is level', 4)
logger.log('debug', 'this is a debug message, which is level', 7)
logger.warn('this is a debug message, which is level', 7)

Now let's stay for some reason, we want to capitalise all the log messages that are warning levels and higher, we can do this by making our own transport by extending the Transform.

const { Logger, Transform, Human } = require('caterpillar')
const logger = new Logger()

const { createWriteStream } = require('fs')
logger.pipe(createWriteStream('./debug.log'))

class Uppercase extends Transform {
    format(entry) {
        if (entry.levelNumber <= 4) {
            entry.args.forEach(function (value, index) {
                if (typeof value === 'string') {
                    entry.args[index] = value.toUpperCase()
                }
            })
        }
        return entry
    }
}

logger.pipe(new Uppercase()).pipe(new Human()).pipe(process.stdout)

logger.log('warn', 'this is a warning, which is level', 4)
logger.warn('this is a warning, which is level', 4)
logger.log('debug', 'this is a debug message, which is level', 7)
logger.warn('this is a debug message, which is level', 7)

Futhermore, the user probably doesn't need to see debug messages, even though they are useful for debugging. We can filter out the debug messages for the user, but maintain them for the debug.log file by applying the Filter transport to the pipe that goes to stdout.

const { Logger, Transform, Filter, Human } = require('caterpillar')
const logger = new Logger()

const { createWriteStream } = require('fs')
logger.pipe(createWriteStream('./debug.log'))

class Uppercase extends Transform {
    format(entry) {
        if (entry.levelNumber <= 4) {
            entry.args.forEach(function (value, index) {
                if (typeof value === 'string') {
                    entry.args[index] = value.toUpperCase()
                }
            })
        }
        return entry
    }
}

logger
    .pipe(new Filter({ filterLevel: 5 }))
    .pipe(new Uppercase())
    .pipe(new Human())
    .pipe(process.stdout)

logger.log('warn', 'this is a warning, which is level', 4)
logger.warn('this is a warning, which is level', 4)
logger.log('debug', 'this is a debug message, which is level', 7)
logger.warn('this is a debug message, which is level', 7)

As fetching line information is computationally expensive process, for large applications for performance we probably only want to fetch the line information for messages that we actually show to the user. As such, we should make the filterLevel and the lineLevel the same.

const { Logger, Transform, Filter, Human } = require('caterpillar')
const level = 5
const logger = new Logger({ lineLevel: level })

const { createWriteStream } = require('fs')
logger.pipe(createWriteStream('./debug.log'))

class Uppercase extends Transform {
    format(entry) {
        if (entry.levelNumber <= 4) {
            entry.args.forEach(function (value, index) {
                if (typeof value === 'string') {
                    entry.args[index] = value.toUpperCase()
                }
            })
        }
        return entry
    }
}

logger
    .pipe(new Filter({ filterLevel: 5 }))
    .pipe(new Uppercase())
    .pipe(new Human())
    .pipe(process.stdout)

logger.log('warn', 'this is a warning, which is level', 4)
logger.warn('this is a warning, which is level', 4)
logger.log('debug', 'this is a debug message, which is level', 7)
logger.warn('this is a debug message, which is level', 7)

Finally, if we are using Caterpillar in web browser environments, instead of Node.js, instead of doing:

const { Logger, Transform, Filter, Human } = require('caterpillar')
// ...
logger.pipe(new Human()).pipe(process.stdout)
// ...

We would pipe to the Browser transform instead of to stdout.

const { Logger, Transform, Filter, Human, Browser } = require('caterpillar')
// ...
logger.pipe(new Human()).pipe(new Browser())
// ...

With this, you now have enough information to leverage the cross-platform power of Caterpillar for most purposes, and the power to write your own custom transforms which can be published as their own packages and shared.

Install

npm

  • Install: npm install --save caterpillar
  • Import: import * as pkg from ('caterpillar')
  • Require: const pkg = require('caterpillar')

Skypack

<script type="module">
    import * as pkg from '//cdn.skypack.dev/[email protected]^6.6.0'
</script>

unpkg

<script type="module">
    import * as pkg from '//unpkg.com/[email protected]^6.6.0'
</script>

jspm

<script type="module">
    import * as pkg from '//dev.jspm.io/[email protected]'
</script>

Editions

This package is published with the following editions:

History

Discover the release history by heading on over to the HISTORY.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

GitHub Sponsors donate button Patreon donate button Flattr donate button Liberapay donate button Buy Me A Coffee donate button Open Collective donate button crypto donate button PayPal donate button Wishlist browse button

Contributors

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

License

Unless stated otherwise all works are:

and licensed under:

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].