Coder Social home page Coder Social logo

bevry / caterpillar Goto Github PK

View Code? Open in Web Editor NEW
401.0 15.0 14.0 2.75 MB

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.

License: Other

TypeScript 98.86% JavaScript 1.14%
transform-streams pipe logger logging client-side nodejs caterpillar deno

caterpillar's People

Contributors

balupton avatar dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar thelfensdrfer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

caterpillar's Issues

Passing options down the pipe

It would be useful to be able to pass options along the pipe.

For example Human has an option color as does Browser, which would typically be set the same. Both default to true, however if you want them to be false then you need to include { color: false } for both.

Instead if Human( opts ) could be passed to Browser etc. both client code and usage would be simplified as { color: false } would only need to be specified once.

Similarly it would be handy if LogEntry could be passed down the pipe then the Browser transform could access LogEntry passed to Human().

Finally it would be useful if Transform's could access Logger options.

I do however realize that these suggestions maybe outside the design scope or even unwanted.

Does default level really work?

Following your document example to the letter but for:

// Import
var level  = process.argv.indexOf('-d') === -1 ? 6 : 7;
var logger = new (require('caterpillar').Logger)({level:level});
var filter = new (require('caterpillar-filter').Filter)();
var human  = new (require('caterpillar-human').Human)();

The following doesn't seem to have any effect:

logger.log('this is level 6, the default level');

Formatting output

I would like to add a line break between each log entry in my file, how can I do that?

flow type complaining with recent flow type version

> flow check

node_modules/caterpillar/source/logger.js:237
237:            const err = new Error()
                            ^^^^^^^^^^^ constructor call
247:                    stack = err.__previous__ && err.__previous__.stack
                                                                     ^^^^^ property `stack`. Property cannot be accessed on
247:                    stack = err.__previous__ && err.__previous__.stack
                                                    ^^^^^^^^^^^^^^^^ property `__previous__` of unknown type

node_modules/caterpillar/source/logger.js:237
237:            const err = new Error()
                            ^^^^^^^^^^^ constructor call
260:                    lines = stack.toString().split('\n')
                                ^^^^^^^^^^^^^^^^ call of method `toString`. Method cannot be called on
260:                    lines = stack.toString().split('\n')
                                ^^^^^ property `__previous__` of unknown type

node_modules/caterpillar/source/logger.js:285
285:                const parts = line.split(':')
                                  ^^^^^^^^^^^^^^^ call of method `split`
 11:    line:number,
             ^^^^^^ number. This type is incompatible with the expected return type of
256:     split(separator: string | RegExp, limit?: number): Array<string>;
                                                                  ^^^^^^ string. See lib: /private/tmp/flow/flowlib_25e12824/core.js:256


Found 3 errors

Getting Started docs needed.

I tried a demo and had a quick look at the docs, but what I'm missing is a plain English getting started section. I'm not into typescript and often find wading through code generated docs painful and I give up and move on. My 2c.

Logger metadata

Various loggers enable metadata to be included in logger output. In Pino etc. this is handled by child loggers. In Consola you can use log.wthTag( name ) to create a logger with a name.

This enables you to know more about the source of log entries. It is especially important when filenames aren't included in the log output, or where filenames are useless such as in the browser when all source files are bundled together in one file.

I can't see a way to accomplish this in caterpillar at present.

My suggestion is to allow a metadata object to be included in Logger( LoggerOptions ). This would then be included in LogEntry and therefore available everywhere.

You would then do new Logger( { metaObj, ... } ) to create the logger instances you needed.

I would also use the metaObj in a Filter() transform to filter out entries matching certain metadata which I'm not interested in at a point in time or only pipe it to a specific target.

problem with deno sample on https://repl.it/@balupton/caterpillar-deno#index.ts

running the sample from https://repl.it/@balupton/caterpillar-deno#index.ts with deno (version 1.4.2) I receive the error

error: Import 'https://unpkg.com/[email protected]/edition-deno/index.ts' failed: 404 Not Found
Imported from "https://unpkg.com/[email protected]/edition-deno/logger.ts:1"

a solution was to import the library not with unpkg.com but with jspm.dev

import { Logger, Filter, Human } from 'https://jspm.dev/caterpillar'

or skypack.dev

import { Logger, Filter, Human } from 'https://cdn.skypack.dev/caterpillar'

In this way the sample works perfectly

logger.log and then process.exit doesn't show anything

When I want to log an error and exit a process nothing gets outputted.

example

if somethingBad
    logger.log "error", "something bad happended"
    process.exit 1

But if I use console.log instead it will output the message.

Is there a way to flush the logger?

LineInfo and Curriyng

I've extended the Logger to be used with Socket.io. I map each log levels to a new method :
log.info(msg) is equal to log('info', msg) but when I log, the lineinfo refers to the logger function, instead of the real place the logging method is called.

Is there a way to configure where to get the stack info from?

lib/logger.js

var _ = require('lodash');

module.exports = function(level){
    var logger = new (require('caterpillar').Logger)({level:level});
    var filter = new (require('caterpillar-filter').Filter)();
    var human  = new (require('caterpillar-human').Human)();

    this.levels = logger.config.levels;

     // Pipe logger output to filter, then filter output to stdout
    logger.pipe(filter).pipe(human).pipe(process.stdout);


      //map  each level to a method
      _.keys(this.levels).map(function mapLevel(levelName){
         logger[levelName] = function(msg){
             return logger.log.apply(logger, [levelName].concat(arguments));
          }
      });

      return logger;
  };

GIving the logger to socket.io

var logger = require('./lib/logger')(7);
var io = require('socket.io').listen(server, {logger : logger});

Then I got this output:

info: { '0': 'socket.io started' }
    → [2013-06-29 17:10:12.018] [anonymous function) [as info] (/home/bertrand/dev/workspace/node-htop/lib/logger.js:28] [Logger.logger.(anonymous function) [as 
```)

Export `ConsoleFormatter`

Hi there!

It doesn't seem like ConsoleFormatter is accessible outside the module -- guess you forgot it in module.exports? :)

Only fetch line info if a new `debug` config option is true (false by default)

Update catepillar-human to use debug property.

This will be a major breaking change. As instead of just doing .setConfig({level: 7}) if they want debugging, they must now also do .setConfig({debug: true, level: 7}).

So will need to have to do something for this... Perhaps something like:

const config = this.getConfig()
const debug = config.debug != null ? config.debug : config.level === 7

However, if we specify a default like false, then the above won't work.

Maybe just gotta break b/c compat.

Would also be interesting to see the performance comparison of this.

More control over formatter config

Hi

It seems that there is no easy way to easily customize the message output in the console. For example while using docpad regularly, I find it a bit cluttered because of the huge size of the filePath / lineNumber every 2 lines.

There may be a way to do it now, by extending the Console Formatter class and overloading the format class but issue #1 has to be fixed to export Console Formatter in the first place.

The ideal will be to be able do to it through config arguments.

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.