@bluewardca/node-logging
v1.0.0
Published
Structured Pino logging and Express request logging for Blueward Node.js services
Maintainers
Readme
@bluewardca/node-logging
Blueward Node.js 서비스용 구조화 로깅 모듈입니다. Pino 기반 로거와 Express 요청/오류 로깅 미들웨어를 제공합니다.
설치
npm install @bluewardca/node-logging기본 사용법
import { createLogger, createLoggerConfig } from '@bluewardca/node-logging';
const config = createLoggerConfig(process.env, { serviceName: 'order-api' });
const logger = createLogger(config);
logger.info('order.created', { orderId: '42' });
logger.error('order.create.failed', error, { orderId: '42' });Express
import express from 'express';
import { createLogger } from '@bluewardca/node-logging';
import {
createErrorLogger,
createRequestContext,
createRequestLogger,
} from '@bluewardca/node-logging/express';
const app = express();
const logger = createLogger({ serviceName: 'order-api' });
app.use(createRequestContext());
app.use(createRequestLogger(logger));
// 라우트 등록 후 오류 응답 미들웨어보다 먼저 등록합니다.
app.use(createErrorLogger(logger));
app.use((err, req, res, next) => {
res.status(err.statusCode || 500).json({ error: err.message });
});기본적으로 비밀번호, 토큰 및 Authorization 헤더를 마스킹합니다. redactPaths로 프로젝트별 필드를 추가할 수 있습니다.
환경변수
SERVICE_NAME: 서비스 이름NODE_ENV: 실행 환경LOG_LEVEL: Pino 로그 레벨LOG_PRETTY: 로컬용 pretty 출력 여부 (true또는false)
npm 배포
먼저 npm whoami 결과가 bluewardca인지 확인해야 합니다. npm 프로필의 표시 이름이 아니라 로그인 사용자명이 scope와 일치해야 합니다.
npm login
npm publish --access public비공개 패키지로 배포하려면 package.json의 publishConfig.access를 restricted로 변경합니다. 비공개 scoped package는 npm 요금제 및 조직 설정에 따라 비용이 발생할 수 있습니다.
