npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

modusign-winston

v1.0.3

Published

custom winston module for modusign logging

Downloads

7

Readme

modusign-winston

A logger for service based node.js

Usage

아래 코드는 기본적인 사용법입니다. 자세한 설정 및 설명은 아래를 참고해주세요.

주의사항 - ES6가 지원되는 node 6 버전 이상만 사용가능합니다.

// inject modusign-winston
const logger = require('modusign-winston');

// level(log level), env(project environment)
const options = { level: 'info', env: 'development' };

// meta data that always include in log
const baseMeta = { service_name: 'modusign-winston' } 

// configure options & baseMeta
logger.configure({ options, baseMeta });

// log it!
logger.info('log message');

Table of Content

Configuration

modusign-winston은 Logger에 자체 대한 설정 객체 options와 Logger가 로그를 찍을 때 마다 항상 포함되는 메타데이터에 대한 설정 객체인 baseMeta를 가지고 있습니다.

logger.configure({ options, baseMeta });

Options

Logger에 자체에 대한 설정 객체인 options는 아래와 같이 이루어집니다.

|Name|Default|Description| |---|---|---| |level|'info'|해당 로그 레벨보다 낮은 레벨을 로그를 찍지 않음| |env|'production'|해당 환경에 맞는 로그 포맷 출력|

Level

Log Level은 아래와 같이 정의 되어 있습니다. 숫자가 적을 수록 로그 레벨이 높습니다. 정의되어 있지 않은 레벨을 사용 할 경우 에러를 던집니다.

{
  test: 0, // 테스트
  error: 1, // 에러
  warn: 2, // 에러는 아니지만 이후 문제가 될 수 있는 사항
  info: 3, // 서비스 운영에 도움이 되는 정보 또는 지표
  debug: 4 // 디버깅
}

Env

환경은 아래와 같이 정의 되어 있습니다. 정의되어 있지 않은 레벨을 사용 할 경우 에러를 던집니다.

|Name|Description| |---|---| |'development'|개발 단계 환경| |'stage'|스테이지 단계 환경| |'production'|배포 단계 환경| |'test'|테스트 단계 환경|

환경에 따라 로그의 출력 포맷이 변합니다. 'development''test' 환경에서는 로그의 출력 포맷이 가독성에 중점을 두었으며 일반 텍스트로 출력되며 가독성을 위해 colorize와 prettyPrint가 적용되어 있습니다.

이에 반해 'stage''production' 환경에서는 로그 정보를 aws-logs로 전송하므로 json 형식으로 변경하여 로그를 출력합니다.

Base Meta

Base Meta는 log를 찍을 때 항상 포함되는 meta data를 설정하는 객체 입니다. Base Meta의 기본값은 빈 객체({}) 입니다.

Logger Configure

아래와 같이 모듈을 주입하게 되면 전역적으로 사용 가능한 logger를 불러 올 수 있습니다.

const logger = require('modusign-winston');

위의 logger는 이전 장 Options와 Base Meta에서 보셨듯이 기본값으로 설정됩니다. 만약 다른 Options과 Base meta를 설정하고 싶다면 아래와 같이 설정하시면 됩니다.

const options = { level: 'error', env: 'production' };
const baseMata = { service_id: 'Account Service' };
logger.configure({ options, baseMeta });

configure 메서드를 통해 options과 baseMeta를 변경할 수 있습니다. configure 메서드는 options와 baseMeta를 key로 가지는 객체를 인자로 받습니다. (이후 Local Logger를 사용할 때도 동일함)

주의할 점 - 옵션이 전달 될 때 기존의 옵션들은 모두 없어지고 전달된 옵션으로만 설정이 됩니다.

Reset Configure

기본값으로 모든 설정을 변경할 때 아래와 같이 reset 메서드를 사용하면 됩니다.

logger.reset();

Logging

위의 설정에서 보았듯이 로그 레벨은 아래와 같이 설정되어 있습니다.

{
  test: 0, // 테스트
  error: 1, // 에러
  warn: 2, // 에러는 아니지만 이후 문제가 될 수 있는 사항
  info: 3, // 서비스 운영에 도움이 되는 정보 또는 지표
  debug: 4 // 디버깅
}

각 레벨의 이름과 동일한 이름의 메서드로 로깅 가능합니다.

const message = 'log message';
logger.debug(message);
logger.info(message);
logger.warn(message);
logger.error(message);
logger.test(message);

그리고 두번째 인자로 메타 데이터 객체를 전달 할 수 있습니다.

const message = 'log message';
const meta = { service_id: 'Account Service' };
logger.info(message, meta);

Create Local Logger

전역 logger와 별도의 옵션을 가진 logger를 만들어 사용하고 싶다면 아래와 같이 할 수 있습니다.

const Logger = require('modusign-winston').Logger;

const options = { level: 'info', env: 'production' };
const baseMeta = { service_id: 'Account Service' };
const logger = new Logger({ options, baseMeta });

생성자 인자들은 기존 configure 메서드의 인자와 동일합니다. 그리고 전역으로 사용되는 logger 동일한 기능을 제공합니다.