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 ๐Ÿ™

ยฉ 2025 โ€“ย Pkg Stats / Ryan Hefner

@codecorn/corn-logger

v1.0.4

Published

๐Ÿง  Logger CodeCorn CLI + Console + File Logger - colorato e strutturato

Readme

๐ŸŒฝ @codecorn/corn-logger

๐Ÿง  Logger TypeScript avanzato per Node.js con supporto a colori, salvataggio su file, sub-contesto e livello log.
Colori, contesto, stack trace, log file, livelli e supporto a .env. Basato su console-log-colors e ottimizzato per ambienti CLI/DevOps.

@codecorn/corn-logger

Downloads npm version GitHub stars GitHub issues Tests MIT License


๐Ÿš€ Installazione

npm install @codecorn/corn-logger

oppure con yarn:

yarn add @codecorn/corn-logger

โš ๏ธ Il logger legge automaticamente variabili da .env se presenti (dotenv.config() รจ incluso).


โœจ Funzionalitร 

  • โœ… Log colorati con contesto e sub-contesto
  • โœ… Livelli: DEBUG, INFO, WARN, ERROR
  • โœ… Logging condizionale su file (process.env.LOG_STORE=true)
  • โœ… Supporto a stack trace errori
  • โœ… Pretty-print JSON e oggetti complessi
  • โœ… Time e date IT friendly (dd/MM/yyyy HH:mm:ss)

๐Ÿ”ง Setup base

// index.ts o bootstrap
import * as dotenv from 'dotenv';
dotenv.config();

import { logInfo, logError, logWarn, logDebug, logMessage } from '@codecorn/corn-logger';

logMessage('DEBUG', 'BOOT', 'Logger pronto ๐Ÿš€');
logInfo('MAIN', 'Tutto ok');
logWarn('INIT', { warning: 'config mancante' });
logError('DB', new Error('Connessione fallita'), 'DBConnect');
logDebug('SERVICE', { id: 123, state: 'running' }, 'JobRunner');

๐Ÿ”ฅ Esempi

logInfo('SERVER', 'Server avviato sulla porta 3000');

logWarn('DB', 'Connessione lenta rilevata', 'Postgres');

logError('API', new Error('Endpoint fallito'), 'GET /api/user');

logDebug('AUTH', { user: 'admin', role: 'superuser' }, 'SessionPayload');

Tutti i log vengono stampati in console colorata e salvati in logs/YYYY-MM-DD.log se LOG_STORE=true.


โš™๏ธ Variabili .env e ๐Ÿ“ฆ Logger su File

Per abilitare la scrittura su file nella directory logs/:

LOG_STORE=true
LOG_DIR=test_log

Se LOG_STORE=true, ogni log sarร  anche salvato in file logs/YYYY-MM-DD.log.

Output nel formato:

[2025-08-05 14:33:05] [SERVICE] DEBUG > JobRunner:
{ id: 123, state: 'running' }

โœจ Features

  • โœ… Colorazione ANSI per ogni livello log
  • โœ… Sub-context support (logError(context, err, subContext))
  • โœ… Supporto a Error, object, string, null, undefined
  • โœ… Salvataggio su file con timestamp (LOG_STORE=true)
  • โœ… Estendibile e minimalista

๐Ÿ”ง Scripts utili

Nel tuo package.json:

"scripts": {
  "build": "tsc",
  "dev": "tsc --watch",
  "lint": "tsc --noEmit",
  "prepare": "npm run build"
}

๐Ÿ—‚ Struttura progetto

corn-logger/
โ”œโ”€โ”€ dist/              # Build finale JS
โ”œโ”€โ”€ src/               # Codice sorgente TS
โ”œโ”€โ”€ types/             # Tipi definiti
โ”œโ”€โ”€ index.ts           # Entry point
โ”œโ”€โ”€ index.ts           # Cli script
โ”œโ”€โ”€ .env               # (opzionale)
โ”œโ”€โ”€ .npmignore
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ tsconfig.json

๐Ÿ›  Integrazione CLI (facoltativa)

Puoi usare il logger anche direttamente da terminale in diversi modi:

โœ… 1. Esecuzione diretta con npx

npx cornlog --context "SYSTEM" --level info --message "Avvio completato"

โœ… 2. Esecuzione tramite npm run

Usa lo script definito nel tuo package.json:

npm run cli -- -c SYSTEM -l info -m "Avvio completato"

Attenzione al doppio --: serve per passare argomenti al comando CLI.


โœ… 3. Esecuzione via npm link (globale)

Se hai eseguito:

npm run build
npm link

Puoi usare direttamente il comando globale ovunque nel sistema:

cornlog -c SYSTEM -l info -m "Avvio completato"

๐ŸŽฏ Altri esempi CLI

cornlog -c DB -l warn -m "Query lenta" -s "postgres"
cornlog -c API -l error -m "Token non valido" -s "AuthMiddleware"
cornlog -c JOB -l debug -m "Task schedulato" -s "cron-runner"
cornlog -c INIT -l info -m "Configurazione caricata"

I log verranno colorati e stampati a terminale. Se LOG_STORE=true nel tuo .env, verranno anche salvati in logs/YYYY-MM-DD.log.


๐Ÿ“– Guida rapida CLI (--help)

Per vedere tutte le opzioni disponibili della CLI, puoi usare:

cornlog --help

Output:

Usage: cornlog [options]

๐Ÿง  Logger CLI CodeCorn - log colorato e opzionale su file

Options:
  -c, --context <context>     Contesto del log (es: SYSTEM, DB, API) [obbligatorio]
  -l, --level <level>         Livello log: info | warn | error | debug [obbligatorio]
  -m, --message <message>     Messaggio da loggare [obbligatorio]
  -s, --sub <subContext>      Sotto-contesto opzionale
  -V, --version               Mostra versione
  -h, --help                  Mostra questo aiuto

โš ๏ธ Tutte le opzioni marcate come obbligatorie devono essere specificate, altrimenti la CLI restituirร  un errore.


๐Ÿงช Test

npm run lint
npm test

๐Ÿ‘ค Maintainer


๐Ÿ“ License

MIT ยฉ CodeCornโ„ข

Distribuito sotto licenza MIT.


๐Ÿค Contribuisci

Pull request benvenute. Per grosse modifiche apri una issue prima di iniziare.

Powered by CodeCornโ„ข ๐Ÿš€