How to use logform - 10 common examples

To help you get started, we’ve selected a few logform 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 DefinitelyTyped / DefinitelyTyped / types / express-winston / express-winston-tests.ts View on Github external
new winston.transports.Console({})
  ],
}));

const logger = winston.createLogger();

// Logger with minimum options (winstonInstance)
app.use(expressWinston.logger({
  winstonInstance: logger,
}));

// Error Logger with all options
app.use(expressWinston.errorLogger({
  baseMeta: { foo: 'foo', nested: { bar: 'baz' } },
  dynamicMeta: (req, res, err) => ({ foo: 'bar' }),
  format: new Format(),
  level: (req, res) => 'level',
  metaField: 'metaField',
  msg: 'msg',
  requestFilter: (req, prop) => true,
  requestWhitelist: ['foo', 'bar'],
  transports: [
    new winston.transports.Console({})
  ]
}));

// Error Logger with min options (transports)
app.use(expressWinston.errorLogger({
  transports: [
    new winston.transports.Console({})
  ],
}));
github hyperledger / caliper / packages / caliper-core / lib / common / utils / log-formats.js View on Github external
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const colors = require('colors/safe');
const { format } = require('logform');
const { LEVEL } = require('triple-beam');

const attributeRegex = /%attribute%/gi;

const colorizeExtra = format((info, opts) => {
    // The immutable level string of the message (the normal property could be mutated already)
    let lev = info[LEVEL];
    // colors enables multiple styles separated by spaces
    let colorStyles = opts.colors[lev].split(' ');

    for (let key of Object.keys(info)) {
        if (info[key] !== undefined && (opts.all || opts[key])) {
            // surround the value with the style codes one by one
            for (let style of colorStyles) {
                try {
                    info[key] = colors[style](info[key]);
                } catch (e) {
                    // silent fail, can't log here
                }
            }
        }
github sourcegraph / sourcegraph / lsif / src / logging.ts View on Github external
const uppercaseTransformer = (info: TransformableInfo): TransformableInfo => {
        info.level = info.level.toUpperCase()
        return info
    }

    const colors = {
        debug: 'dim',
        info: 'cyan',
        warn: 'yellow',
        error: 'red',
    }

    return _createLogger({
        level: LOG_LEVEL,
        // Need to upper case level before colorization or we destroy ANSI codes
        format: format.combine({ transform: uppercaseTransformer }, format.colorize({ level: true, colors }), {
            transform: formatTransformer,
        }),
        defaultMeta: { service },
        transports: [new transports.Console({})],
    })
}
github hyperledger / caliper / packages / caliper-core / lib / common / utils / log-formats.js View on Github external
if (info[key] !== undefined && (opts.all || opts[key])) {
            // surround the value with the style codes one by one
            for (let style of colorStyles) {
                try {
                    info[key] = colors[style](info[key]);
                } catch (e) {
                    // silent fail, can't log here
                }
            }
        }
    }

    return info;
});

const padLevelExtra = format(info => {

    let padding = ' '.repeat(Math.max(5 - info[LEVEL].length, 0));
    info.level = `${info.level}${padding}`;
    return info;
});

const attributeFormat = format((info, opts) => {
    for (let key of Object.keys(info)) {
        if (typeof opts[key] === 'string') {
            if (typeof info[key] !== 'string') {
                info[key] = JSON.stringify(info[key]);
            }

            info[key] = opts[key].replace(attributeRegex, info[key]);
        }
    }
github kubernetes-simulator / simulator / tools / scenario-tools / lib / logger.js View on Github external
const { inspect } = require('util')
const { MESSAGE, SPLAT } = require('triple-beam')
const winston = require('winston')
const { format } = require('logform')

const formatLogMessage = format((info, opts) => {
  const depth = opts.depth || null
  if (info[SPLAT]) {
    for (const splat of info[SPLAT]) {
      info.message += '\n' + inspect(splat, false, depth, opts.colorize)
    }
  }

  info[MESSAGE] = `${info.level}:${info.message}`

  return info
})

// Creates a new logger with the supplied options.
// Options are:
// - colorize - whethers to colourise the output
// - level - the logging level
github namshi / winston-graylog2 / test / e2e.js View on Github external
},
};

const logger = winston.createLogger({
  level: 'debug',
  levels: {
    emerg: 0,
    alert: 1,
    crit: 2,
    error: 3,
    warn: 4,
    notice: 5,
    info: 6,
    debug: 7,
  },
  format: format.combine(format.errors({stack: true}), format.metadata()),
  transports: [new WinstonGraylog2(options)],
});

socket.on('listening', () => {
  let emergCheck;
  let alertCheck;
  let critCheck;
  let errorCheck;
  let warnCheck;
  let noticeCheck;
  let infoCheck;
  let debugCheck;
  const listeners = [];
  const notifyListeners = (msg) => {
    listeners.forEach((listener) => listener(msg));
  };
github new-eden-social / new-eden-social / packages / logger / src / logger.providers.ts View on Github external
useFactory: () => {
      const LOG_LEVEL = process.env.LOG_LEVEL;

      let output = format.json();
      if (process.env.NODE_ENV === 'develop') {
        output = format.combine(
          format.colorize(),
          format.printf((nfo: TransformableInfo) => {
            let formattedOutput = `${nfo.timestamp} ${nfo.level}: ${nfo.message}`;
            if (nfo.metadata && Object.keys(nfo.metadata).length !== 0) {
              formattedOutput += `\n${JSON.stringify(nfo.metadata, null, 4)}`;
            }
            return formattedOutput;
          }),
        );
      }

      return createLogger({
        level: LOG_LEVEL,
        format: format.combine(
          format.metadata(),
          format.timestamp(),
github CacherApp / cacher-run-server / src / lib / server.ts View on Github external
private setupLogger() {
    const level = this.verbose ? 'debug' : 'info';

    const transports = this.logToFile
      ? [new winston.transports.File({ filename: LOG_FILE })]
      : [new winston.transports.Console()];

    this.logger = winston.createLogger({
      level,
      format: format.combine(
        format.colorize(),
        format.timestamp(),
        format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
      ),
      transports
    });
  }
}
github breuerfelix / king-bot-api / src / logger.ts View on Github external
constructor() {
		const logFormat = format.combine(
			//format.colorize(),
			format.align(),
			format.printf((x: any) => `${x.level}: ${x.message}`)
		);

		this.log_inst = winston.createLogger({
			level: 'debug',
			format: logFormat,
			transports: [
				new winston.transports.Console()
			]
		});

		this.logz_inst = winston.createLogger({
			level: 'info',
			transports: [
github new-eden-social / new-eden-social / packages / logger / src / logger.providers.ts View on Github external
if (process.env.NODE_ENV === 'develop') {
        output = format.combine(
          format.colorize(),
          format.printf((nfo: TransformableInfo) => {
            let formattedOutput = `${nfo.timestamp} ${nfo.level}: ${nfo.message}`;
            if (nfo.metadata && Object.keys(nfo.metadata).length !== 0) {
              formattedOutput += `\n${JSON.stringify(nfo.metadata, null, 4)}`;
            }
            return formattedOutput;
          }),
        );
      }

      return createLogger({
        level: LOG_LEVEL,
        format: format.combine(
          format.metadata(),
          format.timestamp(),
          output,
        ),
        transports: [
          new transports.Console(),
        ],
      });
    },
  },

logform

An mutable object-based log format designed for chaining & objectMode streams.

MIT
Latest version published 12 days ago

Package Health Score

89 / 100
Full package analysis