GithubHelp home page GithubHelp logo

articulog's Introduction

articulog

Simple typescript/javascript logging wrapper. Inspired by:

The goals of this project is to do the following:

  • Have a swappable typescript interface for logging
  • Have several log levels that can be adjusted dynamically
  • Have several categories of logs
  • Allow for easy crafting of different log targets
  • Enable a top level control to allow for configuring of logs dynamically, and as a group
  • Create with little to no dependencies (for simple logging)
  • Have this be useful for both browser and nodejs environments

Installation

npm install --save articulog

Usage

Get a basic console log

import {log, LoggerLevel} from 'articulog'

log.info('Hello World!');

log.setLevel(LoggerLevel.SILENT);

log.error('This won't show up');

log.setLevel(LoggerLevel.ERROR);

log.debug('This won't show up either');

log.error('This will show up');

More advanced logs

import {ConsoleLoggerFactory, LoggerLevel} from 'articulog';

ConsoleLoggerFactory.createLog({
  name: 'APILog',
  level: LoggerLevel.WARN,
  methodFactory: (rawMethod: (...msg : Array<any>) => void, methodName: string, level: LoggerLevel, loggerName: string) => {
    return (...msg : Array<any>) => {
      fetch(`http://localhost/logger?msg=${msg[0]}&methodName=${methodName}`);
      rawMethod(...msg);
    };
  }
});

Top level log control

import {LogControl, LoggerLevel}

// Sets the loggers to silent
LogControl.turnOffAllLogs();

// Sets all logs to INFO
LogControl.setAllLogsToLevel(LoggerLevel.INFO);

let logger = LogControl.getLog('APILog');
logger.error('An error occured!');

File logger

On a production nodejs application I would create a custom LoggerFactory that wraps winston functionality. I will add an example soon, but it is just a matter of creating a special factory.

Development

Local Install

npm install

Build

npm run build

Test

npm test

articulog's People

Watchers

Calder Hayes avatar

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.