@gaoding/hlg-logger-v2
Hlg logger v2 sdk
Last updated a year ago by xuezi .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @gaoding/hlg-logger-v2 
SYNC missed versions from official npm registry.

hlg-logger-v2 SDK

安装插件

npm install @gaoding/hlg-logger-v2

基本用法

const config = {
    logStdio: false,                         // 是否输出调试信息,默认:false
    logServer: '<YOUR_LOG_SERVER_ADDR>',    // 日志服务器地址,必填
    level: 'NONE',                           // 日志级别,由高到低:ALL|ERROR|WARN|INFO|NONE,默认:NONE
    host: '<YOUR_HOSTNAME>',                // 应用服务器地址,默认:os.hostname()
    app: '<YOUR_LOG_INDEX_NAME>',             // 应用名称(日志服务的索引名称),必填
    env: 'dev',                            // 应用环境:dev|stage|prod,默认:空字符串
};

// 创建日志实例:方式一
const logger = require('@gaoding/hlg-logger-v2').create(config);

// 创建日志实例:方式二
const logger = new Logger(config);

// 上报不同级别日志
logger.info('message', metadata, type = '', module = '');
logger.warn('message', metadata, type = '', module = '');
logger.debug('message', metadata, type = '', module = '');
logger.error('message', metadata, type = '', module = '');

// 上报埋点
// 注意:metric 函数与 v1 版本完全不兼容
logger.metric(name, targets = [], labels = []);

其他用法

// 通过 metadata 来临时重写日志 env、type、model 值
logger.info('custom-message', {
    log_env: 'dev',
    log_type: 'metadata_log_type_test',
    log_module: 'metadata_log_module_test',
});

// 记录 error 对象
// 注意:如果 log.message == error.message,那么只会上报 log.message,不再重复记录 error.message。
logger.error('custom-message', {
    error: new Error('此错误对象将会被自动解析'),
});

参考文档

Current Tags

  • 1.1.10                                ...           latest (a year ago)

25 Versions

  • 1.1.10                                ...           a year ago
  • 1.1.9                                ...           a year ago
  • 1.1.8                                ...           a year ago
  • 1.1.6                                ...           a year ago
  • 1.1.5                                ...           a year ago
  • 1.1.4                                ...           a year ago
  • 1.1.3                                ...           a year ago
  • 1.1.2                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.15                                ...           a year ago
  • 1.0.14                                ...           a year ago
  • 1.0.13                                ...           a year ago
  • 1.0.12                                ...           a year ago
  • 1.0.11                                ...           a year ago
  • 1.0.10                                ...           a year ago
  • 1.0.9                                ...           a year ago
  • 1.0.8                                ...           a year ago
  • 1.0.7                                ...           a year ago
  • 1.0.6                                ...           a year ago
  • 1.0.5                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago

Copyright 2014 - 2016 © taobao.org |