How to use egg-logger - 10 common examples

To help you get started, we’ve selected a few egg-logger 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 eggjs / egg-cluster / lib / agent_worker.js View on Github external
*/

// $ node agent_worker.js options
const options = JSON.parse(process.argv[2]);
if (options.require) {
  // inject
  options.require.forEach(mod => {
    require(mod);
  });
}

const debug = require('debug')('egg-cluster');
const gracefulExit = require('graceful-process');

const ConsoleLogger = require('egg-logger').EggConsoleLogger;
const consoleLogger = new ConsoleLogger({ level: process.env.EGG_AGENT_WORKER_LOGGER_LEVEL });

const Agent = require(options.framework).Agent;
debug('new Agent with options %j', options);
const agent = new Agent(options);

function startErrorHandler(err) {
  consoleLogger.error(err);
  consoleLogger.error('[agent_worker] start error, exiting with code:1');
  process.exitCode = 1;
  process.kill(process.pid);
}

agent.ready(err => {
  // don't send started message to master when start error
  if (err) return;
github eggjs / egg-cluster / lib / master.js View on Github external
super();
    this.options = parseOptions(options);
    this.workerManager = new Manager();
    this.messenger = new Messenger(this);

    ready.mixin(this);

    this.isProduction = isProduction();
    this.agentWorkerIndex = 0;
    this.closed = false;
    this[REAL_PORT] = this.options.port;
    this[PROTOCOL] = this.options.https ? 'https' : 'http';

    // app started or not
    this.isStarted = false;
    this.logger = new ConsoleLogger({ level: process.env.EGG_MASTER_LOGGER_LEVEL || 'INFO' });
    this.logMethod = 'info';
    if (process.env.EGG_SERVER_ENV === 'local' || process.env.NODE_ENV === 'development') {
      this.logMethod = 'debug';
    }

    // get the real framework info
    const frameworkPath = this.options.framework;
    const frameworkPkg = utility.readJSONSync(path.join(frameworkPath, 'package.json'));

    this.log(`[master] =================== ${frameworkPkg.name} start =====================`);
    this.logger.info(`[master] node version ${process.version}`);
    /* istanbul ignore next */
    if (process.alinode) this.logger.info(`[master] alinode version ${process.alinode}`);
    this.logger.info(`[master] ${frameworkPkg.name} version ${frameworkPkg.version}`);

    if (this.isProduction) {
github eggjs / egg-cluster / lib / app_worker.js View on Github external
'use strict';

// $ node app_worker.js options
const options = JSON.parse(process.argv[2]);
if (options.require) {
  // inject
  options.require.forEach(mod => {
    require(mod);
  });
}

const fs = require('fs');
const debug = require('debug')('egg-cluster');
const gracefulExit = require('graceful-process');
const ConsoleLogger = require('egg-logger').EggConsoleLogger;
const consoleLogger = new ConsoleLogger({
  level: process.env.EGG_APP_WORKER_LOGGER_LEVEL,
});
const Application = require(options.framework).Application;
debug('new Application with options %j', options);
const app = new Application(options);
const clusterConfig = app.config.cluster || /* istanbul ignore next */ {};
const listenConfig = clusterConfig.listen || /* istanbul ignore next */ {};
const httpsOptions = Object.assign({}, clusterConfig.https, options.https);
const port = options.port = options.port || listenConfig.port;
const protocol = (httpsOptions.key && httpsOptions.cert) ? 'https' : 'http';

process.send({
  to: 'master',
  action: 'realport',
  data: {
    port,
github PedroGao / lin-cms-koa-braver / packages / core / lib / extend / logging.js View on Github external
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("../config");
const logger_1 = require("../logger");
const egg_logger_1 = require("egg-logger");
// 默认配置
let options = {
    level: 'INFO',
    dir: 'logs',
    sizeLimit: 1024 * 1024 * 5,
    file: true
};
const logConf = config_1.config.getItem('log');
// 融合配置
options = Object.assign({}, options, logConf);
exports.logger = new egg_logger_1.Logger({});
// 如果file开启,则打开,否则关闭
if (options.file) {
    exports.logger.set('file', 
    // 日志输出到文件
    new logger_1.FileTransport({
        dir: options.dir,
        sizeLimit: options.sizeLimit,
        level: options.level
    }));
}
exports.logger.set('console', 
// 日志输出到终端
new logger_1.ConsoleTransport({
    level: options.level
}));
/**
github TaleLin / lin-cms-koa-core / example / logger.js View on Github external
const Logger = require('egg-logger').Logger;

const { FileTransport } = require('../lin/logger/file');
const { ConsoleTransport } = require('../lin/logger/console');

const logger = new Logger();
logger.set(
  'file',
  new FileTransport({
    dir: 'log',
    sizeLimit: 1024 * 5,
    level: 'DEBUG'
  })
);
logger.set(
  'console',
  new ConsoleTransport({
    level: 'DEBUG'
  })
);

logger.debug('debug foo'); // only output to stdout
github eggjs / egg / lib / core / logger.js View on Github external
module.exports = function createLoggers(app) {
  const loggerConfig = app.config.logger;
  loggerConfig.type = app.type;

  if (app.config.env === 'prod' && loggerConfig.level === 'DEBUG' && !loggerConfig.allowDebugAtProd) {
    loggerConfig.level = 'INFO';
  }

  const loggers = new Loggers(app.config);

  // won't print to console after started, except for local and unittest
  app.ready(() => {
    if (loggerConfig.disableConsoleAfterReady) {
      loggers.disableConsole();
    }
  });
  loggers.coreLogger.info('[egg:logger] init all loggers with options: %j', loggerConfig);

  return loggers;
};
github eggjs / egg-mock / app / extend / application.js View on Github external
mockLog(logger) {
    logger = logger || this.logger;
    if (typeof logger === 'string') {
      logger = this.getLogger(logger);
    }
    // make sure mock once
    if (logger._mockLogs) return;

    const transport = new Transport(logger.options);
    // https://github.com/eggjs/egg-logger/blob/master/lib/logger.js#L64
    const log = logger.log;
    mm(logger, '_mockLogs', []);
    mm(logger, 'log', (level, args, meta) => {
      const message = transport.log(level, args, meta);
      logger._mockLogs.push(message);
      log.apply(logger, [ level, args, meta ]);
    });
  },
github TaleLin / lin-cms-koa-core / lib / logger / file.ts View on Github external
get defaults() {
    // @ts-ignore
    return utils.assign(super.defaults, {
      file: null,
      level: 'INFO'
    });
  }
github midwayjs / pandora / packages / pandora / src / universal / LoggerBroker.ts View on Github external
'use strict';
import {DefaultLoggerManager, ILogger} from 'pandora-service-logger';
import {join} from 'path';
import {EOL} from 'os';
import mzFs = require('mz/fs');

const ConsoleLogger = require('egg-logger').EggConsoleLogger;
export const consoleLogger = new ConsoleLogger({
  level: 'INFO',
});

let daemonLogger = null;

export function getPandoraLogsDir() {
  const {logger: loggerConfig} = lazyGetGlobalConfig();
  return loggerConfig.logsDir;
}

export function getDaemonLogger(): ILogger {
  const {logger: loggerConfig} = lazyGetGlobalConfig();
  if (!daemonLogger) {
    const loggerManager = DefaultLoggerManager.getInstance();
    daemonLogger = loggerManager.createLogger('daemon', {
      ...loggerConfig.daemonLogger,
github eggjs / egg-core / lib / egg.js View on Github external
/**
     * @member {Object} EggCore#options
     * @private
     * @since 1.0.0
     */
    this._options = this.options = options;
    this.deprecate.property(this, '_options', 'app._options is deprecated, use app.options instead');

    /**
     * logging for EggCore, avoid using console directly
     * @member {Logger} EggCore#console
     * @private
     * @since 1.0.0
     */
    this.console = new EggConsoleLogger();

    /**
     * @member {BaseContextClass} EggCore#BaseContextClass
     * @since 1.0.0
     */
    this.BaseContextClass = BaseContextClass;

    /**
     * Base controller to be extended by controller in `app.controller`
     * @class Controller
     * @extends BaseContextClass
     * @example
     * class UserController extends app.Controller {}
     */
    const Controller = this.BaseContextClass;

egg-logger

egg logger

MIT
Latest version published 6 months ago

Package Health Score

76 / 100
Full package analysis

Similar packages