How to use mozlog - 10 common examples

To help you get started, we’ve selected a few mozlog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / fxa / packages / fxa-event-broker / bin / workerDev.ts View on Github external
import { StatsD } from 'hot-shots';
import mozlog from 'mozlog';

import Config from '../config';
import { createDatastore, FirestoreDatastore, InMemoryDatastore } from '../lib/db';
import { ServiceNotificationProcessor } from '../lib/notificationProcessor';
import { proxyServerInit, ServerEnvironment } from '../lib/proxy-server';
import { ClientCapabilityService } from '../lib/selfUpdatingService/clientCapabilityService';
import { ClientWebhookService } from '../lib/selfUpdatingService/clientWebhookService';
import { configureHapiSentry, configureSentry } from '../lib/sentry';
import { version } from '../lib/version';

configureSentry({ enabled: false, release: version.version });

const NODE_ENV = Config.get('env');
const logger = mozlog(Config.get('log'))('notificationProcessor');

// This is a development only server
if (NODE_ENV === 'production') {
  logger.error('workerDev', {
    message: 'NODE_ENV must not be set to production to run the dev server'
  });
  process.exit(1);
}

const firestoreConfig = Config.get('firestore');
const firestoreEnabled = firestoreConfig.enabled;
delete firestoreConfig.enabled;

let db = firestoreEnabled
  ? createDatastore(FirestoreDatastore, firestoreConfig)
  : createDatastore(InMemoryDatastore, { clientWebhooks: Config.get('clientWebhooks') });
github mozilla / fxa / packages / fxa-support-panel / bin / worker.ts View on Github external
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * Primary entry point for running the support panel in production.
 *
 * @module
 */
import mozlog from 'mozlog';

import Config from '../config';
import { init, ServerEnvironment } from '../lib/server';

const logger = mozlog(Config.get('logging'))('supportPanel');

async function main() {
  const server = await init(
    { ...Config.getProperties(), env: Config.get('env') as ServerEnvironment },
    logger
  );

  try {
    logger.info('startup', { message: 'Starting support-panel ...' });
    await server.start();
  } catch (err) {
    logger.error('startup', { err });
    process.exit(1);
  }

  process.on('uncaughtException', err => {
github mozilla / fxa / packages / fxa-basket-proxy / lib / logging / index.js View on Github external
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var mozlog = require('mozlog');
var config = require('../config').get('log');

mozlog.config(config);

var root = mozlog('logging');
if (root.isEnabledFor('debug')) {
  root.warn(
    '\t*** CAREFUL! Louder logs (less than INFO)' + ' may include SECRETS! ***'
  );
}

module.exports = mozlog;
github mozilla / fxa-content-server / server / bin / basket-proxy-server.js View on Github external
#!/usr/bin/env node

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


var url = require('url');
var mozlog = require('mozlog');
var request = require('request');

var config = require('../lib/configuration');
mozlog.config(config.get('logging'));

var logger = require('mozlog')('server.basketproxy');

// Side effect - Adds default_fxa and dev_fxa to express.logger formats
var routeLogging = require('../lib/logging/route_logging');

var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');

var CORS_ORIGIN = config.get('public_url');
var API_KEY = config.get('basket.api_key');
var API_URL = config.get('basket.api_url');
var API_TIMEOUT = config.get('basket.api_timeout');
var VERIFY_URL = config.get('oauth_url') + '/v1/verify';
github mozilla / fxa-auth-server / lib / senders / log.js View on Github external
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict'

var mozlog = require('mozlog')

var logConfig = require('../../config').get('log')

mozlog.config(logConfig)

module.exports = mozlog
github mozilla / fxa-content-server / server / bin / csp-violation-server.js View on Github external
#!/usr/bin/env node

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


var fs = require('fs');
var mozlog = require('mozlog');

var config = require('../lib/configuration');
mozlog.config(config.get('logging'));

var logger = require('mozlog')('server.main');

var express = require('express');
var bodyParser = require('body-parser');

function makeApp() {
  var violations = fs.createWriteStream('violations.txt', {flags: 'a'});
  var app = express();
  app.use(bodyParser.json());
  app.get('/index.html', function (req, res) {
    res.json({result: 'ok'});
  });
  app.post('/_/csp-violation', function (req, res) {
    logger.warn('VIOLATION REPORT');
    var data = {
github mozilla / fxa-content-server / server / bin / null-basket-server.js View on Github external
#!/usr/bin/env node

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


var url = require('url');
var mozlog = require('mozlog');

var config = require('../lib/configuration');
mozlog.config(config.get('logging'));

var logger = require('mozlog')('server.nullbasket');

var express = require('express');
var bodyParser = require('body-parser');

var API_KEY = config.get('basket.api_key');
var API_URL = config.get('basket.api_url');


// Error codes are defined in:
// https://github.com/mozilla/basket-client/blob/master/basket/errors.py
/* eslint-disable sorting/sort-object-props */
var BASKET_ERRORS = {
  NETWORK_FAILURE: 1,
  INVALID_EMAIL: 2,
github mozilla / fxa / packages / fxa-event-broker / bin / generate-sqs-traffix.ts View on Github external
AWS.config.update({
  region: 'us-east-1'
});

/** Total messages to generate before stopping.
 * @constant {number}
 * @default
 */
const MESSAGE_COUNT = 10_000;

const chance = new Chance();

const sqs = new SQS();
const queueUrl = Config.get('serviceNotificationQueueUrl');
const logger = mozlog(Config.get('log'))('generate-sqs-traffic');

// Promisify the AWS send message, the Node promisify mangled the TS signature
const sqsSendMessage = (params: SQS.SendMessageRequest): Promise =>
  new Promise((resolve, reject) => {
    sqs.sendMessage(params, (err, data) => {
      if (err) {
        reject(err);
      } else {
        resolve(data);
      }
    });
  });

/**
 * Queue a SQS message.
 *
github mozilla / fxa / packages / fxa-event-broker / bin / worker.ts View on Github external
import mozlog from 'mozlog';

import { StatsD } from 'hot-shots';
import Config from '../config';
import { createDatastore, FirestoreDatastore, InMemoryDatastore } from '../lib/db';
import { ServiceNotificationProcessor } from '../lib/notificationProcessor';
import { proxyServerInit, ServerEnvironment } from '../lib/proxy-server';
import { ClientCapabilityService } from '../lib/selfUpdatingService/clientCapabilityService';
import { ClientWebhookService } from '../lib/selfUpdatingService/clientWebhookService';
import { configureHapiSentry, configureSentry } from '../lib/sentry';
import { version } from '../lib/version';

// Initialize Sentry as early as possible
configureSentry({ dsn: Config.get('sentryDsn'), release: version.version });

const logger = mozlog(Config.get('log'))('notificationProcessor');

const firestoreConfig = Config.get('firestore');
const firestoreEnabled = firestoreConfig.enabled;
delete firestoreConfig.enabled;

const db = firestoreEnabled
  ? createDatastore(FirestoreDatastore, firestoreConfig)
  : createDatastore(InMemoryDatastore, {});

export function extractRegionFromUrl(url: string) {
  const matchResult = url.match(/(?:.*\/sqs\.)([^\.]+)/i);
  if (!matchResult || matchResult.length !== 2) {
    return undefined;
  } else {
    return matchResult[1];
  }
github mozilla / fxa-oauth-console / lib / config.js View on Github external
* Logging
   */
  logging: {
    default: {
      app: 'fxa-oauth-console',
    },
  },
});

var envConfig = path.join(__dirname, '..', 'config', conf.get('env') + '.json');
var files = (envConfig + ',' + process.env.CONFIG_FILES)
  .split(',')
  .filter(fs.existsSync);
conf.loadFile(files);

require('mozlog').config(conf.get('logging'));
process.env.NODE_ENV = conf.get('env');

conf.validate();

module.exports = conf;

mozlog

Logging utility that outputs records for Heka.

MPL-2.0
Latest version published 3 years ago

Package Health Score

46 / 100
Full package analysis

Popular mozlog functions