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

folder-logger

v1.0.9

Published

πŸ“ A module that helps you sort logs into physical folders according to their importance, save them to a file, and apply text formatting to all logs in batches.

Downloads

15

Readme

Folder-Logger

κ°„νŽΈν•œ 둜그 기둝 관리,

μ€‘μš”λ„μ— λ”°λ₯Έ μžλ™ν™” 된 폴더 λΆ„λ₯˜

λ‚ μ§œμ™€ μ‹œκ°„μ— λ”°λ₯Έ μžλ™ν™” 된 파일 λΆ„λ₯˜

이쁜 κΈ°λ³Έ ν…μŠ€νŠΈ ν¬λ©§νŒ…

Node.js μ—μ„œ μ‰½κ²Œ μ‚¬μš©ν•  수 μžˆλŠ” 둜거 λͺ¨λ“ˆμž…λ‹ˆλ‹€.

μ‚¬μš©λͺ¨μŠ΅

Folder-Logger λŠ” λͺ¨λ“ λ‘œκ·Έμ— 이븐 ν…μŠ€νŠΈ ν¬λ©§νŒ…μ„ μ μš©μ‹œν‚€λŠ” κΈ°λ³Έ κΈ°λŠ₯을 가지고 μžˆμŠ΅λ‹ˆλ‹€. 이 κΈ°λŠ₯은 이용자 ν•„μš”μ— 따라 μ»€μŠ€ν„°λ§ˆμ΄μ§• 될 수 있으며, ν¬λ©§νŒ…μ„ λ„κ±°λ‚˜, μ½˜μ†”μ—” ν‘œμ‹œλ˜μ§€ μ•Šκ³  νŒŒμΌμ—λ§Œ 기둝되게 μ²˜λ¦¬ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.

Bash μ‚¬μš©μ˜ˆ

Windows, Mac μ—μ„œ Bash μ‚¬μš©μ‹œ λ³΄μ—¬μ§€λŠ” λͺ¨μŠ΅μž…λ‹ˆλ‹€. 가급적 Bash 기반 μ½˜μ†”μ„ μ΄μš©ν•  것을 ꢌμž₯ν•©λ‹ˆλ‹€.

Windows CMD μ‚¬μš©μ˜ˆ

Folder-Logger 의 κΈ°λ³Έ ν…μŠ€νŠΈ ν¬λ©§νŒ…μ€ μ–΄λ– ν•œ λ³€ν˜•λ„ μ—†λŠ” Windows κΈ°λ³Έ CMD 도 κ³ λ €ν•˜μ—¬ κ΅¬μ„±λ˜μ–΄μžˆμŠ΅λ‹ˆλ‹€.

ν΄λ”λ‘œ λΆ„λ₯˜λœ 둜그 데이터 예

Folder-Logger λŠ” 둜그 μ€‘μš”λ„μ— 둜그λ₯Ό λΆ„λ₯˜ν•΄μ„œ 각기 λ‹€λ₯Έ 폴더에 μ €μž₯ν•©λ‹ˆλ‹€. μ΄λ ‡κ²Œ μ €μž₯λ˜λŠ” ν΄λ”λŠ” λ‚ μ§œμ— λ”°λΌμ„œ μ €μž₯λ˜λ―€λ‘œ, μ°Ύκ³  μžˆλŠ” μ€‘μš”λ„μ™€ λ‚ μ§œμ™€ μ‹œκ°„μ— ν•΄λ‹Ήν•˜λŠ” 둜그λ₯Ό μ–΄λ– ν•œ μ—λ””ν„°μ—μ„œλ“  ν”ŒλŸ¬κ·ΈμΈ λ˜λŠ” 검색없이 물리적 폴더 및 파일 λΆ„λ₯˜λ‘œ μ‰½κ²Œ 찾을 수 μžˆμŠ΅λ‹ˆλ‹€.

μ €μž₯λ˜λŠ” 둜그 데이터 예

ν…μŠ€νŠΈμ— μ–΄λ– ν•œ ANSI 컬러λ₯Ό μ‚¬μš©ν•˜κ±°λ‚˜ 특수문자λ₯Ό μ‚¬μš©ν•΄λ„, λ‘œκ·Έμƒμ—μ„œ 깨지지 μ•Šκ³  μ½˜μ†”μ—μ„œ ν‘œμ‹œλœ Unicode κ°€ κΉ”λ”ν•˜κ²Œ μ‹œκ°„κ³Ό ν•¨κ»˜ μ •λ¦¬λ©λ‹ˆλ‹€. μ €μž₯λ˜λŠ” λ‘œκ·Έν˜•νƒœλŠ” μ΄μš©μžκ°€ 직접 μ»€μŠ€ν„°λ§ˆμ΄μ§• ν•  수 있으며, μ΄λŸ¬ν•œ 둜그 ν¬λ©§νŒ…μ€ λ‘œκ·Έμ— 따라 자유둭게 끄고 μΌ€ 수 μžˆμŠ΅λ‹ˆλ‹€.

μ‚¬μš© 방법

λͺ¨λ“ˆ μ„€μΉ˜

npm install --save folder-logger

둜거 생성

둜그λ₯Ό μ €μž₯ν•  ν΄λ”κ²½λ‘œλ₯Ό 미리 λ§Œλ“€κ±°λ‚˜, λ‘œκ·ΈνŒŒμΌμ„ μƒˆλ‘œ λ§Œλ“€ ν•„μš”λŠ” μ—†μŠ΅λ‹ˆλ‹€. μ§€μ •λœ ν΄λ”κ²½λ‘œλ‚΄ 폴더 계측이 μ—†λŠ” 경우 폴더λ₯Ό μƒμ„±ν•˜λ©°, 둜그 νŒŒμΌλ„ μžλ™μœΌλ‘œ μƒμ„±ν•©λ‹ˆλ‹€. (λ˜ν•œ ν”„λ‘œκ·Έλž¨μ΄ λ‹€μ‹œ μΌœμ§€λ”λΌλ„ λ‘œκ·Έκ°€ μ΄ˆκΈ°ν™”λ˜λŠ” ν˜„μƒ 없이 μ—°μ†λœ 둜그 μž‘μ„±μ΄ μ΄λ€„μ§‘λ‹ˆλ‹€.)

// ES5
const FolderLogger = require('folder-logger')

// 둜그λ₯Ό μ €μž₯ν•  ν΄λ”μœ„μΉ˜
const path = `${__dirname}/logs/`

// 둜거 μΈμŠ€ν„΄μŠ€ 생성
const logger = new FolderLogger(path)

둜거 λ©”μ‹œμ§€ 전솑

var message = `Lorem ipsum dolor sit amet`

// κΈ°λ³Έ μ•ˆλ‚΄ λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€.
logger.info(message)

// μ‹œμŠ€ν…œ λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€.
logger.system(message)

// 주의 λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€.
logger.warn(message)

// 였λ₯˜ λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€.
logger.error(message)

// 치λͺ…적 였λ₯˜ λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€.
logger.critical(message)

// λ””λ²„κΉ…μš© λ©”μ‹œμ§€λ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€.
logger.debug(message)

둜거 레벨 λΆ„λ₯˜

Folder-Logger 의 둜그 λΆ„λ₯˜λŠ” 총 6가지이며, 이 6가지 λΆ„λ₯˜μ—” 0~5κΉŒμ§€μ˜ μ€‘μš”λ„ λΆ„λ₯˜κ°€ μ‘΄μž¬ν•©λ‹ˆλ‹€.

const level = {
    info: 0,
    system: 1,
    warn: 2,
    error: 3,
    critical: 4,
    debug: 5
}

μœ„μ™€ 같은 level κ°μ²΄λŠ” μ•„λž˜μ™€ 같은 λ°©λ²•μœΌλ‘œ 둜거 μƒμ—μ„œ μ–Έμ œλ“  κ°€μ Έμ˜¬ 수 μžˆμŠ΅λ‹ˆλ‹€.

// μœ„μ˜ level 객체λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
logger.level()

// level 객체의 key 값듀을 λ°˜ν™˜ν•©λ‹ˆλ‹€.
logger.levelNames()

둜거 레벨 μ„€μ •

Folder-Logger μ—λŠ” μ½˜μ†”μ— ν‘œμ‹œλ˜λŠ” 둜그 λ©”μ‹œμ§€μ˜ λ ˆλ²¨μ„ μ„€μ •ν•  수 μžˆλŠ” κΈ°λŠ₯이 μžˆμŠ΅λ‹ˆλ‹€. κ°€λ Ή 3을 μ„€μ •ν•œ 경우, 3 보닀 더 큰 레벨의 λ‘œκ·ΈλŠ” μ½˜μ†” 상에 ν‘œμ‹œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. μ„€μ •λœ 둜그 레벨과 상관없이 파일 μƒμ—λŠ” μ •μƒμ μœΌλ‘œ λͺ¨λ“  λ‘œκ·Έκ°€ 기둝 λ©λ‹ˆλ‹€. (기본적으둜 μ„€μ •λœ 둜거 λ ˆλ²¨μ€ 5μž…λ‹ˆλ‹€.)

// 이 경우 debug λ©”μ‹œμ§€λ₯Ό ν‘œμ‹œν•˜μ§€ μ•Šκ²Œ λ©λ‹ˆλ‹€.
logger.setLevel(4)

// 이 경우 info λ©”μ‹œμ§€ λ§Œμ„ ν‘œμ‹œν•˜κ²Œ λ©λ‹ˆλ‹€.
logger.setLevel(0)

κ³ κΈ‰ μ‚¬μš© 방법

둜거 λ©”μ‹œμ§€ μ˜΅μ…˜ 적용

logger.info(`Hello?`, {
    noPrint: false, // κΈ°λ³Έ false
    noWrite: false // κΈ°λ³Έ false
    noFormat: false, // κΈ°λ³Έ false
})

μ˜΅μ…˜μ€ info, system, warn, error, critical, debug λͺ¨λ“  ν•¨μˆ˜μ— λ™μΌν•˜κ²Œ 2번째 인자 객체둜 ꡬ성할 수 μžˆμŠ΅λ‹ˆλ‹€. μ•„λž˜μ—μ„œ ν•΄λ‹Ή μ˜΅μ…˜ μš”μ†Œλ“€μ„ μ„€λͺ…ν•©λ‹ˆλ‹€.

noPrint

ν•΄λ‹Ή μ˜΅μ…˜μ΄ true 둜 처리되면 μ½˜μ†”μƒμ— ν•΄λ‹Ή λ©”μ‹œμ§€κ°€ 좜λ ₯λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. ν•΄λ‹Ή μ˜΅μ…˜μ„ μ΄μš©ν•΄μ„œ ν™”λ©΄μ—” ν‘œμ‹œλ˜μ§€ μ•Šκ³  νŒŒμΌμƒμ—λ§Œ κΈ°λ‘λ˜λŠ” λ‘œκ·Έλ©”μ‹œμ§€λ₯Ό κ΅¬ν˜„ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

noWrite

ν•΄λ‹Ή μ˜΅μ…˜μ΄ true 둜 처리되면 파일 상에 ν•΄λ‹Ή λ©”μ‹œμ§€κ°€ κΈ°λ‘λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. ν•΄λ‹Ή μ˜΅μ…˜μ„ μ΄μš©ν•΄μ„œ ν™”λ©΄μ—λ§Œ ν‘œμ‹œλ˜κ³  νŒŒμΌμƒμ—λŠ” κΈ°λ‘λ˜μ§€ μ•ŠλŠ” λ‘œκ·Έλ©”μ‹œμ§€λ₯Ό κ΅¬ν˜„ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

noFormat

ν•΄λ‹Ή μ˜΅μ…˜μ΄ true 둜 처리되면 ν•΄λ‹Ή λ©”μ‹œμ§€μ— κΈ°λ³Έ ν…μŠ€νŠΈ ν¬λ©§νŒ…μ„ μ μš©ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. μ΄λŠ” νŒŒμΌμ— μ €μž₯λ˜λŠ” λ©”μ‹œμ§€μ™€ μ½˜μ†” 상에 ν‘œμ‹œλ˜λŠ” λͺ¨λ“  λ©”μ‹œμ§€μ— λ™μΌν•©λ‹ˆλ‹€. 이 μ˜΅μ…˜μ„ μ‚¬μš©ν•œμ±„λ‘œ 둜그λ₯Ό μ €μž₯ν•˜κ²Œ 되면 ν•΄λ‹Ή λ©”μ‹œμ§€κ°€ λ°œμƒν•œ μ‹œκ°„μ΄ κΈ°λ‘λ˜μ§€ μ•ŠμœΌλ―€λ‘œ μ£Όμ˜ν•΄μ„œ μ‚¬μš©ν•΄ν•©λ‹ˆλ‹€.

둜거 λ©”μ‹œμ§€ μ €μž₯μœ„μΉ˜ λ³€κ²½

μ•„λž˜ ν•¨μˆ˜λ₯Ό μ΄μš©ν•΄μ„œ λͺ¨λ“ˆμ΄ μ‹€ν–‰ 쀑에 둜거 λ©”μ‹œμ§€μ˜ μ €μž₯ μœ„μΉ˜λ₯Ό λ³€κ²½ν•  수 μžˆμŠ΅λ‹ˆλ‹€. κΈ°μ‘΄ 둜그 νŒŒμΌμ€ μžλ™μœΌλ‘œ μ•Œμ•„μ„œ λ‹«νžˆλ©° 둜그 폴더 κ²½λ‘œκ°€ μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” 경우 μžλ™μœΌλ‘œ 폴더계측과 파일이 μƒμ„±λ©λ‹ˆλ‹€.

// μƒˆλ‘­κ²Œ 둜그λ₯Ό μ €μž₯ν•  폴더 μœ„μΉ˜
const path = `${__dirname}/logs/`

// 둜그 μ €μž₯μœ„μΉ˜λ₯Ό λ³€κ²½ν•©λ‹ˆλ‹€.
logger.setLogPath(path)

log ν•¨μˆ˜ 이용

ν•¨μˆ˜λͺ…을 레벨 λΆ„λ₯˜μ— 따라 λ‹€λ₯΄κ²Œ μ‚¬μš©ν•˜κ³  싢지 μ•Šμ€ 경우, μ•„λž˜μ™€ 같이 log ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜λ©΄μ„œ μ˜΅μ…˜μœΌλ‘œ 둜그 λ ˆλ²¨μ„ 지정해쀄 μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. (둜그 λ ˆλ²¨μ„ μ§€μ •ν•˜μ§€ μ•Šμ€ 경우 info 레벨이 μžλ™μœΌλ‘œ μ μš©λ©λ‹ˆλ‹€.)

logger.log({
    level: logger.level.info // 0~5μœΌλ‘œλ„ μž…λ ₯κ°€λŠ₯ν•©λ‹ˆλ‹€.
})

μ»€μŠ€ν„°λ§ˆμ΄μ§• 방법

둜그파일 ν™•μž₯자 λ³€κ²½

기본적으둜 μ €μž₯λ˜λŠ” 둜그파일 ν™•μž₯μžλŠ” .log μž…λ‹ˆλ‹€. λ‹€λ₯Έ ν™•μž₯자λͺ…을 μ‚¬μš©ν•˜κΈΈ μ›ν•˜λŠ” 경우 이λ₯Ό 둜거 μΈμŠ€ν„΄μŠ€ μƒμ„±μ‹œ 2번째 인자 객체둜 지정할 수 μžˆμŠ΅λ‹ˆλ‹€.

// 둜거 μΈμŠ€ν„΄μŠ€ 생성
const logger = new FolderLogger(path, {
    ext: `txt` // 이 경우 .txt ν™•μž₯자둜 μ €μž₯λ©λ‹ˆλ‹€.
})

둜그파일 μ‹œκ°„ν¬λ©§νŒ… λ³€κ²½

Folder-Logger μ—μ„œ λ‘œκ·ΈνŒŒμΌμ— μ‚¬μš©λ˜λŠ” μ‹œκ°„ ν¬λ©§νŒ…μ€ moment.js λͺ¨λ“ˆμ— μ˜μ‘΄ν•˜κ³  있으며, moment.js μ—μ„œ ν˜Έν™˜ν•˜λŠ” λ‚ μ§œν¬λ©§νŒ…μœΌλ‘œ 자유둭게 λ³€ν˜•ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 즉 λ¬Έμžμ—΄ ν˜•νƒœλ‘œ λ‚ μ§œ ν˜•νƒœλ₯Ό 지정할 수 μžˆμŠ΅λ‹ˆλ‹€. 기본적으둜 μ§€μ •λœ λ‚ μ§œ ν¬λ©§νŒ…μ€ YYYY-MM-DD μž…λ‹ˆλ‹€.

// 둜거 μΈμŠ€ν„΄μŠ€ 생성
const logger = new FolderLogger(path, {
    timeFormat: `YYYY-MM-DD` // 예: 2019-02-06
})

둜그파일 μ‹œκ°„ν¬λ©§νŒ…μ— moment.js μ˜΅μ…˜ 적용

Folder-Logger μ‚¬μš© 쀑 νƒ€μž„μ‘΄ μ„€μ • λ“± moment(/* μ—¬κΈ° */) ν˜•νƒœμ— 직접 μ‚¬μš©ν•΄μ•Όν•˜λŠ” moment.js μ˜΅μ…˜μ΄ μ‘΄μž¬ν•œλ‹€λ©΄ λ‹€μŒκ³Ό 같이 μ μš©κ°€λŠ₯ν•©λ‹ˆλ‹€.

// 둜거 μΈμŠ€ν„΄μŠ€ 생성
const logger = new FolderLogger(path, {
    momentOption: `2090-11-11T11:11:11`
})

둜그 ν…μŠ€νŠΈ ν¬λ©§νŒ… λ³€κ²½

Folder-Logger 의 μ»€μŠ€ν„°λ§ˆμ΄μ§•μ‹œ μ‚¬μš©λ˜λŠ” ν…μŠ€νŠΈ ν¬λ©§νŒ…μ€ μ΄μš©μžμ— μ˜ν•΄ 자유둭게 μ»€μŠ€ν„°λ§ˆμ΄μ§• 될 수 μžˆμŠ΅λ‹ˆλ‹€. μ‚¬μš©λ°©λ²•μ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

// ν¬λ©§νŒ… μ‹œ μ‚¬μš© ν•  μƒ‰μƒν‘œν˜„ λͺ¨λ“ˆμž…λ‹ˆλ‹€.
const chalk = require('chalk')

// ν¬λ©§νŒ… ν•¨μˆ˜ (κΈ°λ³Έν•¨μˆ˜λ₯Ό μ˜ˆμ‹œλ‘œ λ™λ΄‰ν•©λ‹ˆλ‹€.)
const myLogFormat = (log, level, logger) => {
    let defaultFormat ='%time%  %level%  \t\b\b\b\b' + '%log%'
    let time = moment(logger.momentOption).format('HH:mm:ss')
    let levelName = String(logger.levelNames[level]).toUpperCase()
    switch(levelName){
        case 'CRITICAL':
            time = chalk.bgRedBright(chalk.black(time))
            levelName = chalk.bgRedBright(chalk.black(levelName))
            log = chalk.bgRedBright(chalk.black(log))
            break
        case 'WARN':
            time = chalk.bgYellowBright(chalk.black(time))
            levelName = chalk.bgYellowBright(chalk.black(levelName))
            log = chalk.bgYellowBright(chalk.black(log))
            break
        case 'ERROR':
            time = chalk.bgRedBright(chalk.white(time))
            levelName = chalk.bgRedBright(chalk.white(levelName))
            log = chalk.bgRedBright(chalk.white(log))
            break
        case 'DEBUG':
            time = chalk.greenBright(time)
            levelName = chalk.greenBright(levelName)
            log = chalk.greenBright(log)
            break
        case 'SYSTEM':
            time = chalk.yellowBright(time)
            levelName = chalk.yellowBright(levelName)
            log = chalk.yellowBright(log)
            break

        default:
            time = chalk.white(time)
            levelName = chalk.white(levelName)
            log = chalk.white(log)
            break
    }
    let text = defaultFormat
        .replace('%time%', time)
        .replace('%level%', levelName)
        .replace('%log%', log)
    return text
}

// 둜거 μΈμŠ€ν„΄μŠ€ 생성
const logger = new FolderLogger(path, {
    logFormat: myLogFormat
})

둜고 μ•„μ΄μ½˜ 좜처

License

MIT Licensed.