1.0.0 • Published 6 years ago

@schwarzhirsch/logger v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

Logger

Logger built on the winston logger

npm version

Install

$ npm install @schwarzhirsch/logger

Usage

An example will be the @schwarzhirsch/logger can be used.

import logger, { chalk } from '@schwarzhirsch/logger';
 
logger.name('MyClass');
 
class MyClass {
    constructor() {
        logger.info(`
            Schwarzhirsch Logger built on the the
            ${chalk.magenta.underline('winston')}
            logger
        `);
 
        this.bar = {
            foo: 'foo',
            bar: 'bar',
        };
    }
 
    myMethod() {
        logger.info(':myMethod', 'is called');
 
        const promise = new Promise((resolve) => {
            resolve({
                foo: 'foo',
                bar: this.bar,
            });
        });
 
        promise.then((value) => {
            logger.debug(':promise', value);
 
            throw new Error('oh, no!');
        }).catch((e) => {
            logger.error(':myMethod -> promise', e);
        });
    }
}
 
const test = new MyClass();
test.myMethod();

The recommended way to use original winston is to create your own logger. The simplest way to do this is using.

import { winston } from '@schwarzhirsch/logger';
 
const logger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    transports: [
        //
        // - Write to all logs with level `info` and below to `combined.log` 
        // - Write all logs error (and below) to `error.log`.
        //
        new winston.transports.File({ filename: 'error.log', level: 'error' }),
        new winston.transports.File({ filename: 'combined.log' })
    ]
});
 
//
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
// 
if (process.env.NODE_ENV !== 'production') {
    logger.add(new winston.transports.Console({
        format: winston.format.simple()
    }));
}

License

The MIT License

Copyright 2018 Schwarzhirsch Kreativagentur GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.0.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago