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

@baronote/logger

v1.2.22

Published

Sorizava Baronote logger

Downloads

84

Readme

@baronote/logger

logger

Description

winston, morgan를 이용한 logger 별도의 설정없이 사용을 위해 구성

Logger 사용 방식 변경 Trace,Pid 기본 표시 -> 설정 방식으로 변경

Installation

$ npm i @baronote/logger 
// express 에서 사용할 경우 다음과 같이 사용하면 log는 별도 import 불필요
import {morganMiddleware} from "@baronote/logger";

// middleware 사용 미사용 시
import "@baronote/logger"

Configure

로그 출력 구성 default >>[YYYYMMDD HH:mm:ss.SSS] [LogType] ▷ Message pidOn >> [YYYYMMDD HH:mm:ss.SSS] [LogType] [PID] ▷ Message TraceOn >> [YYYYMMDD HH:mm:ss.SSS] [traceFile:line] [LogType] ▷ Message

process.env.NODE_ENV 구성에 따른 level

  • maxSize : 2mb
  • maxFiles : 30 day
  • location : ${ROOT_DIR}\logs
  • files
    • ${NODE_ENV}-${DATETIME}.log : info 레벨의 로그가 적재
    • ${NODE_ENV}-${DATETIME}-error.log : error 레벨의 로그가 적재
    • ${NODE_ENV}-${DATETIME}-http.log : http 레벨의 로그가 적재 단, http 로그의 경우 morganMiddleware를 적용한 경우에만 적재 됩니다.
    • 그 외 (.${HASH}-audit.json) : maxFiles 옵션으로 인해 로그에 대한 관리를 위해 생성되는 파일로 존재하지 않을 경우 로그파일 삭제,압축 등 작업이 이루어지지 않습니다.

Example

Trace or Pid 출력 설정 (global)

import "@baronote/logger";
isTrace = true;
isPid = true;

log.i('normal "info" Log example');
log.w('normal "warn" Log example');
log.e('normal "error" Log example');
log.d('normal "debug" Log example');

Trace or Pid 출력 설정 (function)

import {pidOn, traceOn} from "@baronote/logger";
traceOn();
pidOn();

log.i('normal "info" Log example');
log.w('normal "warn" Log example');
log.e('normal "error" Log example');
log.d('normal "debug" Log example');

일반 사용 예시 입니다.

import "@baronote/logger";

log.i('normal "info" Log example');
log.w('normal "warn" Log example');
log.e('normal "error" Log example');
log.d('normal "debug" Log example');

인자값 예시 입니다.

import "@baronote/logger";

log.i('argument Number print example', 1234);
log.i('argument String print example', 'example');
log.i('argument Short Object print example', {example: 'test'});
log.i('argument Array print example', [1, 2, 3, 4]);
log.i('argument Long Object print example', {example: 'test', example2: {object: 'long', object2: 'long2'}});
log.i('Mult argument print example', 1234, 'example', {example: 'test'}, [1, 2, 3, 4]);

// 그외 출력은 ``를 이용한 방식 사용
log.i(`${'example'} ==> ${{example: 'test'}} || ${JSON.stringify({example: 'test'})}`);

변수 사용 예시 입니다.

import "@baronote/logger";

log.i(1234);
log.i({example: 'test'});
log.i([1, 2, 3, 4]);
log.i({example: 'test', example2: {object: 'long', object2: 'long2'}});
log.i(1234, 'example', {example: 'test'}, [1, 2, 3, 4]);

에러 예시 입니다.

import "@baronote/logger";

let err = new Error('error Example..');
log.e(err);
throw err;

Express Logger 사용

morgan 로그는 combined 을 기본으로 사용합니다.

:remote-addr - :remote-user ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"

import express from 'express';
import {morganMiddleware} from "@baronote/logger";

const app = express();
const port = process.env.PORT || 5000;

app.use(morganMiddleware());

app.all('/info', (req, res, next) => {
    log.i('info test');
    res.status(200).send({
        message: "info test!"
    })
});

app.listen(port, () => log.i(`Server Start Listening on port ${port}`));

History

1.1.2

  • 추가 : 모듈 난독화

1.1.3

  • 수정 : 기본 *.log 파일의 적재 레벨 관련 수정

1.1.4

  • 수정 : import 방식 변경

1.1.5

  • 수정 : node:process 관련 수정

1.1.6

  • 수정 : 기본 로그 출력 포멧 변경
  • 추가 : traceOn, pidOn function
  • 수정 : process 패키지 미사용 방식으로 변경

1.1.7

  • 수정 : 오탈자 수정

1.1.8

  • 수정 : 라이센스 주소
  • 수정 : install 수정
  • 추가 : 히스토리 접기 추가

1.1.9

  • 수정 : boolean 형 출력 안되는 문제 수정

1.1.22

  • 추가 : 로그 kafka 전송 옵션
  • 추가 : TraceID 설정 추가 ( Rest, gRPC )

LICENSE

MIT

(The MIT License)

Copyright (c) 2022 baronote <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.