11#!/usr/bin/env node
2- import { logInfo , logError , logWarn , logDebug } from './index' ; // ⚠️ Usa path corretto se transpili in `dist/`
32import { program } from 'commander' ;
3+ import { logInfo , logError , logWarn , logDebug } from './index.js' ; // ⚠️ Usa path corretto se transpili in `dist/`
44
5- program . name ( 'cornlog' ) . description ( '🧠 Logger CLI CodeCorn - log colorato e opzionale su file' ) . version ( '1.0.2' ) ;
5+ program
6+ . name ( 'cornlog' )
7+ . description ( '🧠 Logger CLI CodeCorn - log colorato e opzionale su file' )
8+ . version ( '1.0.3' )
9+ . requiredOption ( '-c, --context <context>' , 'Contesto del log (es: SYSTEM, DB, API)' )
10+ . requiredOption ( '-l, --level <level>' , 'Livello log: info | warn | error | debug' )
11+ . requiredOption ( '-m, --message <message>' , 'Messaggio da loggare' )
12+ . option ( '-s, --sub <subContext>' , 'Sotto-contesto opzionale' ) ;
613
7- program . requiredOption ( '-c, --context <context>' , 'Contesto del log (es: SYSTEM, DB, API)' ) . requiredOption ( '-l, --level <level>' , 'Livello log: info | warn | error | debug' ) . requiredOption ( '-m, --message <message>' , 'Messaggio da loggare' ) . option ( '-s, --sub <subContext>' , 'Sotto-contesto opzionale' ) . parse ( ) ;
14+ program . on ( '--help' , ( ) => {
15+ console . log ( '' ) ;
16+ console . log ( '📌 Esempi:' ) ;
17+ console . log ( '' ) ;
18+ console . log ( ' ✅ Log semplice' ) ;
19+ console . log ( ' $ cornlog -c SYSTEM -l info -m "Avvio completato"' ) ;
20+ console . log ( '' ) ;
21+ console . log ( ' ✅ Log con sub-context' ) ;
22+ console . log ( ' $ cornlog -c DB -l error -m "Connessione fallita" -s DBConnect' ) ;
23+ console . log ( '' ) ;
24+ console . log ( ' ✅ Usabile anche con npm run:' ) ;
25+ console . log ( ' $ npm run cli -- -c API -l warn -m "Endpoint lento"' ) ;
26+ console . log ( '' ) ;
27+ console . log ( ' ✅ Salvataggio su file' ) ;
28+ console . log ( ' Abilita via .env: LOG_STORE=true' ) ;
29+ console . log ( '' ) ;
30+ } ) ;
31+
32+ program . parse ( ) ;
833
934const opts = program . opts ( ) ;
1035
@@ -14,19 +39,19 @@ const msg = opts.message;
1439const sub = opts . sub || null ;
1540
1641switch ( lvl ) {
17- case 'info' :
18- logInfo ( ctx , msg , sub ) ;
19- break ;
20- case 'warn' :
21- logWarn ( ctx , msg , sub ) ;
22- break ;
23- case 'error' :
24- logError ( ctx , new Error ( msg ) , sub ) ;
25- break ;
26- case 'debug' :
27- logDebug ( ctx , msg , sub ) ;
28- break ;
29- default :
30- console . error ( `❌ Livello non valido: ${ lvl } ` ) ;
31- process . exit ( 1 ) ;
42+ case 'info' :
43+ logInfo ( ctx , msg , sub ) ;
44+ break ;
45+ case 'warn' :
46+ logWarn ( ctx , msg , sub ) ;
47+ break ;
48+ case 'error' :
49+ logError ( ctx , new Error ( msg ) , sub ) ;
50+ break ;
51+ case 'debug' :
52+ logDebug ( ctx , msg , sub ) ;
53+ break ;
54+ default :
55+ console . error ( `❌ Livello non valido: ${ lvl } ` ) ;
56+ process . exit ( 1 ) ;
3257}
0 commit comments