0.0.2 • Published 7 years ago

loggout v0.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

Logg Out

Dead simple yet powerful ES6+ logger for the browser

Developped with Babel, webpack, Jest and :heart:


TODO:

  • : switch to rollup
  • : build system Travis
  • : update stack with logger

Motivation

This logger has been created for 2 main reasons

  1. Having my own simple and lightweight reusable logger
  2. As my first npm package

Usage

Here is the simplest way to init and use the logger. You can find more examples in the examples/ directory of this repo.

import Loggout from 'loggout';
const logger = new Loggout({
    level: Loggout.LEVELS.info;
});

logger.error('Hello world');

Table of Contents

Installation

npm install loggout
yarn add loggout

Logging Options

{
    level: Loggout.LEVELS.info,
    prefix: level => `LOGG(${level}):`,
}

level

Log levels follows RFC5424 ordering.

static get LEVELS() {
    return {
        silly: 10,
        debug: 20,
        verbose: 30,
        info: 40,
        warn: 50,
        error: 60,
    };
}

Default level: error

Levels can be assessed through Loggout.LEVELS constant.

Prefix

Prefix options expects a function receiving the level as parameter and returning a string.

(level) => {
    const ts = Date.now();
    switch (level) {
        case Loggout.LEVELS.silly:
            return `SILLY - ${ts}:`;
        case Loggout.LEVELS.debug:
            return `DEBUG - ${ts}:`;
        case Loggout.LEVELS.verbose:
            return `LOG - ${ts}:`;
        case Loggout.LEVELS.info:
            return `INFO - ${ts}:`;
        case Loggout.LEVELS.warn:
            return `WARN - ${ts}:`;
        case Loggout.LEVELS.error:
            return `ERROR - ${ts}:`;
        default:
            return '';
    }
}

Contribute

File structure

loggout/
 ├──src/                             * our source files that will be compiled to javascript
 |   ├──app/                         * Lib sources
 │   │
 |   └──examples/                    * examples sources
 │       ├──index.pug                * our index.html
 │       │
 │       ├──html/                    * where you keep your pug templates
 │       │   └──layout.pug           * the main pug layout
 │       │
 │       └──app/                     * JavaScript/ES2015 files
 │
 ├──test/                            * Jest test definitions
 │
 ├──webpack/                         * Webpack configuration files
 │   ├──webpack.config.base.js       * Base config
 │   ├──webpack.config.js            * Development overrides
 │   └──webpack.config.prod.js       * Production overrides
 │
 └──package.json                     * package.json

Getting Started

Dependencies

You need to install the following on you system

  • node and npm
  • Ensure you running Node version >= 8.0.0

Installing

Running the app

After all dependencies are installed, just run make start to start a local server using webpack-dev-server which will watch your files and build them. webpack-dev-server will display the address and port of your server (by default, http://0.0.0.0:3000).

Build commands

Server

# build files then launch the server and watch files
make start

Build files

# build files in ./build/ (Webpack, Sass, Pug) and validate them
make build
# "compile" files in ./dist/
# minify and concatenate assets
make release

Validate files

# runs the validations eslint and jest tests
make test

License

MIT

Author: Frank Gairal