Giter Club home page Giter Club logo

logs's Introduction

quave:logs

quave:logs is a Meteor package that allows you to send logs to loggly, from client and server.

Why

Every application needs log and we take advantage of Meteor methods to also send logs from the client.

We don't load heavy dependencies in the client instead we use Meteor methods to send the logs from the client to the server and then to the final destination and to the server console.

We believe we are not reinventing the wheel in this package but what we are doing is like putting together the wheels in the vehicle :).

Installation

meteor add quave:logs
meteor npm install winston-loggly-bulk

Usage

You need to configure this package using your settings.

You have two important fields:

  • sendToServer: define the levels that are going to the server from client logs
  • loggly: token, subdomain and tags to configure loggly. You can also provide an array of Strings messagesToSkip then if the log contains this message it won't be sent.
{
  "public": {
    "env": "DEVELOPMENT",
    "packages": {
      "quave:logs": {
        "sendToServer": [
          "error",
          "warn"
        ],
        "loggly": {
          "token": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
          "subdomain": "yourdomain",
          "tags": [
            "myproject"
          ]
        }
      }
    }
  }
}

We have three methods in the logger object:

  • info
  • warn
  • error

they all receive:

  • message: text
  • error: error object
  • tags: array of tags

Now you are ready to use quave:logs, as we don't want to include server dependencies in the client we need to use a different import in the client.

See one example for server and one for client below.

On server

import { logger } from 'meteor/quave:logs/logger';

client.sendEmail(
    options,
    error => {
      if (error) {
        logger.error({
          message: `Error while sending email=${JSON.stringify(options)}, to=${
            options.to.email
          }`,
          error,
          tags: ['email'],
        });
      }
    }
);

On client

import { loggerClient } from 'meteor/quave:logs/loggerClient';

if (Meteor.userId) {
  loggerClient.info({message: `logged user id ${Meteor.userId}`});
}

If you have your environment on Meteor.settings.public.env it will be sent as a tag automatically.

Limitations

We are using loggly because we like this tool then for now we only support sending logs to loggly. If you don't want to send to anywhere, you can just omit this setting. Also, if you want to support more tools you can submit a PR.

License

MIT

logs's People

Contributors

filipenevola avatar

Stargazers

 avatar

Watchers

 avatar  avatar

logs's Issues

TypeError: transport is not a constructor

In my server/startup.jsx I added this:

import { logger } from 'meteor/quave:logs/logger'

Not sure if that's necessary as I'm only concerned about this on the client side.

In my client/functions/error.js I have this:

import { loggerClient } from 'meteor/quave:logs/loggerClient'
window.onerror = function (message, url, lineNo, columnNo, error) {                                                                                               
  loggerClient.error({ message,error })
}

In my settings.json I have this under "public" --> "packages"

        "quave:logs": {
            "sendToServer": [
                "error"
            ],
            "loggly": {
                "token": "key-goes-here",
                "subdomain": "submithub.com",
                "tags": [
                    "submithub"
                ]
            }
        } 

And that results in this error:

W20210512-11:23:12.463(2)? (STDERR) TypeError: transport is not a constructor
W20210512-11:23:12.464(2)? (STDERR)     at exports.Logger.Logger.add (/Users/jasongrishkoff/code/submithub/node_modules/winston/lib/winston/logger.js:475:41)
W20210512-11:23:12.464(2)? (STDERR)     at Object.winston.<computed> [as add] (/Users/jasongrishkoff/code/submithub/node_modules/winston/lib/winston.js:87:34)
W20210512-11:23:12.464(2)? (STDERR)     at module (packages/quave:logs/logger.js:27:11)
W20210512-11:23:12.464(2)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:336:7)
W20210512-11:23:12.464(2)? (STDERR)     at Module.require (packages/modules-runtime.js:238:14)
W20210512-11:23:12.465(2)? (STDERR)     at require (packages/modules-runtime.js:258:21)
W20210512-11:23:12.465(2)? (STDERR)     at /Users/jasongrishkoff/code/submithub/.meteor/local/build/programs/server/packages/quave_logs.js:345:15
W20210512-11:23:12.465(2)? (STDERR)     at /Users/jasongrishkoff/code/submithub/.meteor/local/build/programs/server/packages/quave_logs.js:350:3
W20210512-11:23:12.465(2)? (STDERR)     at /Users/jasongrishkoff/code/submithub/.meteor/local/build/programs/server/boot.js:401:38
W20210512-11:23:12.465(2)? (STDERR)     at Array.forEach (<anonymous>)
W20210512-11:23:12.465(2)? (STDERR)     at /Users/jasongrishkoff/code/submithub/.meteor/local/build/programs/server/boot.js:226:21
W20210512-11:23:12.465(2)? (STDERR)     at /Users/jasongrishkoff/code/submithub/.meteor/local/build/programs/server/boot.js:464:7
W20210512-11:23:12.465(2)? (STDERR)     at Function.run (/Users/jasongrishkoff/code/submithub/.meteor/local/build/programs/server/profile.js:280:14)
W20210512-11:23:12.465(2)? (STDERR)     at /Users/jasongrishkoff/code/submithub/.meteor/local/build/programs/server/boot.js:463:13

As soon as I remove the loggly part from my config json the error goes away.

"Module is not installed" in the Webstorm

I following your instruction to npm install your package and the system is working. However , in the editor of the webstorm, i shows: Module is not installed at 'meteor/quave:logs/loggerClient'. Any suggestion.

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.