Giter Club home page Giter Club logo

mozlog's Introduction

mozlog

NPM version Build Status

A logger that outputs JSON that adheres to Heka's expected schema.

npm install --save mozlog

Usage

You must create a mozlog instance before using it's loggers. This is essentially setting the app name, the level, and the fmt.

For the brave (or those who know intel's configuration options), you can pass a config property to have fine-grained control.

// create your mozlog instance
const mozlog = require('mozlog')({
  app: 'fxa-oauth-server',
  level: 'verbose', //default is INFO
  fmt: 'pretty', //default is 'heka'
  uncaught: 'exit', // default is 'log', also available as 'ignore'
  debug: true, //default is false
  stream: process.stderr //default is process.stdout
});

You may want the level set down to verbose or debug when developing. Likewise, you may want the line to be readable by humans when developing, so the pretty formatter will help.

In production, the defaults will serve you well: info and heka.

var log = mozlog('routes.client.register');

log.info(op, { some: details });
// such as
log.debug('newClient', { id: client.id, name: client.name });

First parameter is a string "op". It should be unique within the file. Second parameter is some optional object, with keys and values that would make sense when looking at the logs again.

The debug option (not level) in the config will add in some asserts that your usage adheres to the above: that there's only ever at most 2 arguments to a log function, the first is a string without spaces.

mozlog's People

Contributors

dannycoates avatar devinreams avatar eoger avatar jrgm avatar julienw avatar mozilla-github-standards avatar rfk avatar seanmonstar avatar vladikoff avatar whd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mozlog's Issues

Running mocha with MozLog break the stdout.

Expecting:

 2) websockets "after each" hook:

Uncaught AssertionError: expected 2 to deeply equal 3

at stopTest (/home/travis/build/mozilla-services/loop-server/test/websockets_test.js:867:39)
at WebSocket.<anonymous> (/home/travis/build/mozilla-services/loop-server/test/websockets_test.js:875:11)
at WebSocket.emit (events.js:117:20)
at WebSocket.cleanupWebsocketResources (/home/travis/build/mozilla-services/loop-server/node_modules/ws/lib/WebSocket.js:782:23)
at Socket.emit (events.js:117:20)
at _stream_readable.js:944:16
at process._tickCallback (node.js:442:13)

Receiving:

{"Timestamp":1420554568651000000,"Logger":"mozilla-loop-server","Type":"TypeError: undefined is not a function","Severity":0,"Pid":5937,"EnvVersion":"2.0"}

Include TypeScript declarations

I had to make my own typescript declaration file in fxa to use mozlog. Ideally we should have the declarations in this package.

CODE_OF_CONDUCT.md file missing

As of January 1 2019, Mozilla requires that all GitHub projects include this CODE_OF_CONDUCT.md file in the project root. The file has two parts:

  1. Required Text - All text under the headings Community Participation Guidelines and How to Report, are required, and should not be altered.
  2. Optional Text - The Project Specific Etiquette heading provides a space to speak more specifically about ways people can work effectively and inclusively together. Some examples of those can be found on the Firefox Debugger project, and Common Voice. (The optional part is commented out in the raw template file, and will not be visible until you modify and uncomment that part.)

If you have any questions about this file, or Code of Conduct policies and procedures, please see Mozilla-GitHub-Standards or email [email protected].

(Message COC001)

Set protected status on production branch

The production branch on this repository is not protected against force pushes. This setting is recommended as part of Mozilla's Guidelines for a Sensitive Repository.

Anyone with admin permissions for this repository can correct the setting using this URL.

If you have any questions, or believe this issue was opened in error, please contact us and mention SOGH0001 and this repository.

Thank you for your prompt attention to this issue.
--Firefox Security Operations team

Consider Sentry integration

Most of our projects using Sentry only use its integrations. Our lambda's and standalone SQS processors don't have Sentry integration and rely on ops reading logs to find errors.

We should consider having mozlog's error logging be capable of integrating and reporting the error via Sentry. A custom logger handler can be configured to do this, and could look to see if the arg passed is either an Error or has an Error object in it for Sentry reporting.

Child logger objects

When working with logging frameworks, it's often really nice to be able to associate a context of structured logging properties with a specific instance of a logger. We're investigating using Mozlog in Taskcluster:
taskcluster/taskcluster-rfcs#35, but we'd like to have child loggers available. To give an example, we might want to make a logger available in our request handlers which knows the http method and path of the request, without needing to set those properties directly.

An possible example of how such a feature could be used would be:

let rootLogger = new Log();
let childLogger = rootLogger.child({prop1: 'property one'});
childLogger.info({prop2: 'property two'}, 'hello');

would print something along the lines of {prop1: 'property one', prop2: 'property two', msg='hello'};`

Is adding this functionality something which would be merged into this library, or should we do it in a wrapper (or some other system)?

Unconstructive error message 'AssertionError: First arg must be op'

The profile server on latest.dev.lcip.org was failing and continually restarting. In the error log was this unconstructive reason, converted from what was really going wrong (which is an invalid config setting I think).

assert.js:93
  throw new assert.AssertionError({
        ^
AssertionError: First arg must be op
    at Object.conf.filters.debug [as filter] (/data/fxa-profile-server/node_modules/mozlog/lib/index.js:42:16)
    at Logger.filter (/data/fxa-profile-server/node_modules/mozlog/node_modules/intel/lib/filterer.js:9:27)
    at Logger.handle (/data/fxa-profile-server/node_modules/mozlog/node_modules/intel/lib/logger.js:213:14)
    at Logger._log (/data/fxa-profile-server/node_modules/mozlog/node_modules/intel/lib/logger.js:249:20)
    at Logger.critical (/data/fxa-profile-server/node_modules/mozlog/node_modules/intel/lib/logger.js:81:19)
    at Logger.catchException (/data/fxa-profile-server/node_modules/mozlog/node_modules/intel/lib/logger.js:192:10)
    at process.emit (events.js:95:17)
    at process._fatalException (node.js:301:26)

Crash while trying to log uncaughtException

{"Timestamp":1463009371241000000,"Logger":"fxa-basket-proxy",
 "Type":"uncaughtException","Severity":0,"Pid":15654,"EnvVersion":"2.0",
 "Fields":{"error":"TypeError: Cannot set property 'stack' of undefined","stack":"
    at HekaFormatter.hekaFormat [as format] (/data/fxa-basket-proxy/node_modules/mozlog/lib/format.js:94:22)
    at StreamHandler.format (/data/fxa-basket-proxy/node_modules/mozlog/node_modules/intel/lib/handlers/handler.js:52:28)
    at StreamHandler.streamEmit [as _emit] (/data/fxa-basket-proxy/node_modules/mozlog/node_modules/intel/lib/handlers/stream.js:21:27)
    at StreamHandler.emit (/data/fxa-basket-proxy/node_modules/mozlog/node_modules/intel/lib/handlers/handler.js:13:15)
    at Logger.handle (/data/fxa-basket-proxy/node_modules/mozlog/node_modules/intel/lib/logger.js:218:29)
    at Logger.handle (/data/fxa-basket-proxy/node_modules/mozlog/node_modules/intel/lib/logger.js:226:15)
    at Logger._log (/data/fxa-basket-proxy/node_modules/mozlog/node_modules/intel/lib/logger.js:249:20)
    at Logger.error (/data/fxa-basket-proxy/node_modules/mozlog/node_modules/intel/lib/logger.js:81:19)
    at Request.<anonymous> (/data/fxa-basket-proxy/lib/basket/index.js:19:14)
    at Request.emit (events.js:117:20)
    at null._onTimeout (/data/fxa-basket-proxy/node_modules/request/request.js:765:12)
    at Timer.listOnTimeout [as ontimeout] (timers.js:121:15)
"}}

Travis CI free usage ends Dec 3; mozilla repos should switch to other CI platforms

We're opening this issue because your project has used Travis CI within the last 6 months. If you have already migrated off it, you can close and ignore this issue.

Travis CI is ending free builds on public repositories. travis-ci.com stopped providingthem in early November, and travis-ci.org will stop after December 31, 2020. To avoid disruptions to your workflows, you must migrate to another CI service.

For production use cases, we recommend switching to CircleCI. This service is already widely used within Mozilla. There is a guide to migrating from Travis CI to CircleCI available here.

For non production use cases, we recommend either CircleCI or Github Actions. There is a guide to migrating from Travis CI to Github Actions available here. Github Actions usage within Mozilla is new, and you will have to work with our github administrators to enable specific actions following this process.

If you have any questions, reach out in #github-admin:mozilla.org on matrix.

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.