Giter Club home page Giter Club logo

strif's Introduction

NPM Version Downloads Dependencies Known Vulnerabilities
NPM Package Quality NPM Package Size All Contributors

An easy and customizable logger for NodeJS and the Browser.
If you want to log easily or create some complex loggin system, this might be the tool for you!


πŸ”§ Demo πŸ““ Wiki
πŸ”— Logger πŸ”— Notifier πŸ”— Log πŸ”— Severity πŸ”— Formatter
πŸ”— .logger πŸ”— .notifier πŸ”— .severity πŸ”— .formatter


News

  • Browser support is beeing deprecated, development will be discontinued and will be removed from Loggin'JS in version 2.0.0. It's beeing deprecated because it's limiting me on the features I could be adding to the NodeJS version.

Table Of Content

Usefull links:

Installing

$ npm i loggin-js
#Β or
$ yarn add loggin-js

Importing

const loggin = require('loggin-js');
// Or
import * as loggin from 'loggin-js';

Browser

!! NOTICE !!

Loggin'JS can be used in the browser, but it's still in it's early stages, and the API may change or have errors.

It is also limited. For now, only the console notifier works. Color is not working either!

<!-- Import from node_modules -->
<script src="node_modules/loggin-js/dist/loggin.js"></script>

<script>
  LogginJS.logger();
</script>

You can also use a CDN:

<script src="https://cdn.jsdelivr.net/npm/loggin-js@latest/dist/loggin.js"></script>

Getting Started

The default logger is the simplest way to use Loggin'JS.

loggin.debug(
  'Check this log out!!',
  { foo: 'var' },
  { channel: 'my-logger' }
);

Example Output 1

Additionaly you can create a custom logger:

const logger = loggin.logger({
  level: loggin.severity('info'), // Will output only info level and below
  channel: 'demo-1',
  formatter: 'long',
});

logger.user('Jhon');
logger.color(true);

logger.debug('Debug message, will not output');
logger.info('Info message, will output');

// You can override options when executing .log or any default methods (ie: debug, info, etc...)
logger.error('There was an <%rERROR>', null, { user: 'Bob' });

You can also log to a file:

const logger = loggin.logger('file');
logger.channel('my-logger');

logger.getNotifier('file').pipe(loggin.pipe('DEBUG', './debug.log'));

loggin.debug('Check this log out!!', { foo: 'var' });

Or output log in JSON format:

const logger = loggin.logger({
  formatter: 'json',
});

logger.error('this is an error');

There are a couple of default Notifiers available:

  • NodeJS: file, console, http, memory
  • Browser: console, http

Chek out the wiki for a more detailed guide.

back to top


Examples

Here are some usage examples:

If you want to add an example or find some error, leave an issue or send in a PR.

Plugins

Coming:

  • Telegram
  • Mail - maybe?
  • Sentry, and similar
  • ...

Coverage

Coverage Coverage Coverage Coverage

Contributing

First off, thank you for considering contributing to Loggin'JS.

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests. There is also a public slack channel available.

Contributors ✨

Initial work by nombrekeff

Thanks goes to these wonderful people (emoji key):


Manolo Edge

πŸ’» πŸ€” 🚧 ⚠️

Floki

πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

strif's People

Contributors

dependabot[bot] avatar nombrekeff avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

floki-gh

strif's Issues

Allow prop transformers to be functions

Transformers passed into template props, should also accept functions, not only by name.

const format = strif.template('...', {
  props: {
    name: {
      accessor: 'user.name',
      transformers: [
        'capitalize', 
        s => `[${s}]`, // like this
      ]
    }
  }
});

What if...

What if instead of doing this, if just one transformer is applied:

const format = strif.template('{name} has {messageCount} messages', {
  props: {
    name: {
      transformers: ['capitalize']
    }
  }
});

We could do something like:

const format = strif.template('{name | capitalize} has {messageCount} messages');

Dont require property to be defined in props

This should work fine, use prop name message as the accessor:

  formatter.template('[{time}] - {severity} - {message}', {
    props: {
      time: {
        transformers: ['date']
      },
      severity: {
        transformers: ['string']
      }
    }
  });

Now it requires to define the prop:

  formatter.template('[{time}] - {severity} - {message}', {
    props: {
      time: {
        transformers: ['date']
      },
      severity: {
        transformers: ['string']
      },
      message: { }
    }
  });

Global transformers

Add global transformers that apply to all templates generated by a formatter.

const formatter = strif.create({
  transformers: {
    trim: s => s.trim()
  },
  active: [  'trim'  ]
});

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.