Giter Club home page Giter Club logo

pine's Introduction

pine

Build Status

A simple logging wrapper for Winston.

Usage

var pine = require('pine');

var log = pine();
log.info('Hello, world!');
log.error('This Department Has Worked %d Days Without Injury', 0);
[2014-05-22 21:00:39.704 UTC] - info: [26195:index.js] Hello, world!
[2014-05-22 21:00:39.705 UTC] - error: [26195:index.js] This Department Has Worked 0 Days Without Injury

API

pine([name] [,options])

  • name (optional, String) - If not provided, defaults to file path relative to parent package.
  • options (optional, Object) - Same options as pine.configure. When provided will create logger with provided settings, using configured global settings as defaults.

Invoke pine directly to get a logger instance. The API of the logger is determined by the configured levels, which defaults to npm levels: silly, debug, verbose, info, warn, error. Additionally, there is a log method which accepts the desired level as it's first argument. Each method also supports util.format-like string interpolation.

var log = pine();
log.silly('Uptime: %d days', 10);
log.debug('Helpful information');
log.verbose('More information');
log.info('Did you know...');
log.warn('Well, actually...');
log.error('Iceberg!');

pine.configure(options);

  • options - The default options which will be used for all loggers. The options object supports the following optional keys:
    • basedir - The root directory against which relative paths are calculated. Defaults to root of calling module.
    • levels - The winston levels to use. Defaults to npm levels.
    • colors - The colors to use. Defaults to npm colors. whether the client should reject a response from a server with invalid certificates. This cannot be set at the same time as the agent option is set.
    • transports - The transports to use, mapping the transport name to settings. To use external or custom transports see the modules config options.
    • modules - Describe, for registration, the modules which implement the required custom transport.
    • exceptionHandlers - Transports to be used for logging exceptions. An object mapping the transport name to settings.

Set global logging settings, using built-in settings as defaults.

pine.configure({

    basedir: __dirname,

    levels: undefined,

    colors: undefined,

    transports: {
        console: {
            level: 'debug'
        },
        mongodb: {
            level: 'info',
            db: 'logs',
            host: '127.0.0.1',
            port: '27017'
        }
    },

    modules: {
        mongodb: {
            name: 'winston-mongodb',
            property: 'MongoDB'
        }
    },

    exceptionHandlers: undefined
});

pine.settings

Read-only property of current global default settings.

pine's People

Contributors

totherik avatar pvenkatakrishnan avatar gabrielcsapo avatar tlivings avatar athahar avatar

Stargazers

 avatar Vince Rabsatt avatar  avatar Anthony avatar Andi N. Dirgantara avatar Christian Ceciliano avatar Thiago Rodrigues avatar Jeff Prestes avatar Muly Oved avatar Marko Jankovic avatar Tom avatar Kevin Ridgway avatar Alireza Ahmadi avatar Hengki Sihombing avatar

Watchers

Jeff Prestes avatar James Cloos avatar Michael Stramel avatar Matt Edelman avatar subeesh chothendavida avatar Shaun Warman avatar  avatar Kumar Rishav avatar Ryan Magoon avatar  avatar Sumeet Kakkar avatar Ezekiel Keator avatar  avatar

pine's Issues

Updating docs

Hi,

I'm a newcomer to pine, and I think the README should be updated with examples of how to use the file transport, and how to use pine within kraken, because apparently if you just try to replace the default "logger" middleware it doesn't work.
EDIT: If you try to use libs or index as middleware it doesn't work, if you try to do app.use() it says it requires middleware functions. Maybe it's not made to be used as a middleware? If that's the case, do you think we could work out together a plan to make it usable as a middleware? Because I think it fits the use as a middleware...
Also side question, if it's supposed to be used a middleware, how to use it inside a router ?

Thank you !

Issue with multiple util.format placeholders

When trying to use util.format placeholder, it's not correctly inserting values. I compared with console.log:

Test:

log.debug('%s:%s', 'first', {second:true});
console.log('%s:%s', 'first', {second:true});

Output:

debug: [6042:lib/test-read.js] first:%s second=true
first:{"second":true}

Not sure how to add mongo transport to winston...

Because pine obscures winston somewhat, it's not clear the appropriate way to manipulate the winston transports. And in fact the mongo transport tries to copy from one property (dbUri) to other config properties (e.g. db) and because of the "deepFreeze" call... Fails. It'd be great if we made it clear how users of pine are meant to interact with transports.

Multiple file transports?

I don't think it's possible to create multiple file transport via configuration...

    return pine(name, {
        transports: {
            file: {
                level: 'debug',
                filename: 'server.log'
            },
            // Error file logging
            file: {
                level: 'error',
                filename: 'error.log'
            }
        }
    });

I also registering winston-file as a module but it doesn't work either:

    return pine(name, {
        transports: {
            file: {
                name: 'file.debug',
                level: 'debug',
                filename: 'server.log'
            },
            // Error file logging
            fileError: {
                name: 'file.error',
                level: 'error',
                filename: 'error.log'
            }
        },
        modules: {
            fileError: {
                name: 'winston/lib/winston/transports',
                property: 'File'
            }
        }

But this doesn't work either, because you're using definition.property as the new transport name.

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.