Skip to content

Commit 5e47a13

Browse files
committed
s
1 parent 263cc25 commit 5e47a13

11 files changed

Lines changed: 659 additions & 1499 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,7 @@ logs/
142142
*.tsbuildinfo
143143
.DS_Store
144144
.idea/
145-
.vscode/
145+
.vscode/
146+
147+
_STASHED/
148+
/_STASHED

_STASHED/_ODL_cli copy.BAK

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env tsx
2+
import { logInfo, logError, logDebug, logWarn } from './src/consoleHelpers';
3+
import * as dotenv from 'dotenv';
4+
dotenv.config();
5+
6+
const args = process.argv.slice(2);
7+
8+
if (args.length < 1) {
9+
logWarn('CLI', 'Nessun argomento fornito', 'Usage: cli.ts --message "Ciao mondo"');
10+
process.exit(1);
11+
}
12+
13+
const msgArg = args.find((a) => a.startsWith('--message'));
14+
const msg = msgArg ? msgArg.split('=')[1] || 'Messaggio non specificato' : 'Messaggio mancante';
15+
16+
logInfo('CLI', msg, 'Avvio');
17+
18+
try {
19+
// Simula operazione
20+
if (msg === 'fail') throw new Error('Simulazione fallimento');
21+
logDebug('CLI', { success: true, msg }, 'Operazione completata');
22+
} catch (e) {
23+
logError('CLI', e, 'Errore generato');
24+
}

_STASHED/_old_dist/cli.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
export {};

_STASHED/_old_dist/cli.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env node
2+
"use strict";
3+
Object.defineProperty(exports, "__esModule", { value: true });
4+
const index_js_1 = require("./dist/index.js"); // ⚠️ Usa path corretto se transpili in `dist/`
5+
const commander_1 = require("commander");
6+
commander_1.program.name('cornlog').description('🧠 Logger CLI CodeCorn – log colorato e opzionale su file').version('1.0.0');
7+
commander_1.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();
8+
const opts = commander_1.program.opts();
9+
const ctx = opts.context;
10+
const lvl = opts.level.toLowerCase();
11+
const msg = opts.message;
12+
const sub = opts.sub || null;
13+
switch (lvl) {
14+
case 'info':
15+
(0, index_js_1.logInfo)(ctx, msg, sub);
16+
break;
17+
case 'warn':
18+
(0, index_js_1.logWarn)(ctx, msg, sub);
19+
break;
20+
case 'error':
21+
(0, index_js_1.logError)(ctx, new Error(msg), sub);
22+
break;
23+
case 'debug':
24+
(0, index_js_1.logDebug)(ctx, msg, sub);
25+
break;
26+
default:
27+
console.error(`❌ Livello non valido: ${lvl}`);
28+
process.exit(1);
29+
}

_STASHED/_old_dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './src/consoleHelpers';

_STASHED/_old_dist/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"use strict";
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
var desc = Object.getOwnPropertyDescriptor(m, k);
5+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6+
desc = { enumerable: true, get: function() { return m[k]; } };
7+
}
8+
Object.defineProperty(o, k2, desc);
9+
}) : (function(o, m, k, k2) {
10+
if (k2 === undefined) k2 = k;
11+
o[k2] = m[k];
12+
}));
13+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14+
Object.defineProperty(o, "default", { enumerable: true, value: v });
15+
}) : function(o, v) {
16+
o["default"] = v;
17+
});
18+
var __importStar = (this && this.__importStar) || (function () {
19+
var ownKeys = function(o) {
20+
ownKeys = Object.getOwnPropertyNames || function (o) {
21+
var ar = [];
22+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23+
return ar;
24+
};
25+
return ownKeys(o);
26+
};
27+
return function (mod) {
28+
if (mod && mod.__esModule) return mod;
29+
var result = {};
30+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31+
__setModuleDefault(result, mod);
32+
return result;
33+
};
34+
})();
35+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
36+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37+
};
38+
Object.defineProperty(exports, "__esModule", { value: true });
39+
const dotenv = __importStar(require("dotenv"));
40+
dotenv.config(); // ⚠️ Deve stare prima di accedere a process.env
41+
__exportStar(require("./src/consoleHelpers"), exports); // Esporta tutto il logger
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { color, log, red, green, cyan, cyanBright, whiteBright, white, whiteBG, bgWhite, bgYellowBright, bgCyanBright, blueBright, yellow, magenta } from 'console-log-colors';
2+
type LogLevel = 'ERROR' | 'WARN' | 'INFO' | 'DEBUG';
3+
type ColorFn = (input: string) => string;
4+
/**
5+
* Funzione di esempio per mostrare l'utilizzo delle funzioni di colorazione.
6+
* Stampa un oggetto JSON formattato con chiavi colorate.
7+
*/
8+
declare const usage: () => void;
9+
/**
10+
* Funzione per colorare e formattare il JSON come stringa con chiavi e valori personalizzati.
11+
*
12+
* @param {Object} obj - Oggetto JSON da formattare e colorare.
13+
* @param {Function} keyColor - Funzione di colore applicata alle chiavi.
14+
* @param {Function} valueColor - Funzione di colore applicata ai valori.
15+
* @param {Function|null} bgColor - Funzione per il colore di sfondo delle chiavi.
16+
* @param {Function|null} textDecoration - Funzione per decorazione testo (es. bold, italic).
17+
* @param {number} indent - Livello di indentazione iniziale.
18+
* @returns {string} - Stringa JSON formattata con chiavi e valori colorati.
19+
*/
20+
declare const colorizeKeysAsString: (obj: Record<string, any>, keyColor?: ColorFn, valueColor?: ColorFn, bgColor?: ColorFn | null, textDecoration?: ColorFn | null, indent?: number) => string;
21+
/**
22+
* Variante di `colorizeKeysAsString` con indentazione specifica per ogni livello e valori colorati.
23+
*
24+
* @param {Object} obj - Oggetto JSON da formattare e colorare.
25+
* @param {Function} keyColor - Funzione di colore applicata alle chiavi.
26+
* Default: `color.magenta`.
27+
* @param {Function} valueColor - Funzione di colore applicata ai valori.
28+
* Default: `color.green`.
29+
* @param {Function|null} bgColor - Colore di sfondo delle chiavi (opzionale). Default: `null`.
30+
* @param {Function|null} textDecoration - Decorazione testo delle chiavi (opzionale). Default: `null`.
31+
*
32+
* @returns {string} - JSON formattato con indentazione e chiavi colorate.
33+
*/
34+
declare const colorizeKeysAsStringIndent: (obj: Record<string, any>, keyColor?: ColorFn, valueColor?: ColorFn, bgColor?: ColorFn | null, textDecoration?: ColorFn | null, indent?: number) => string;
35+
/**
36+
* Funzione per logging generico con supporto per oggetti JSON.
37+
*
38+
* @param {string} level - Livello del log (INFO, DEBUG, WARN, ERROR).
39+
* @param {string} context - Contesto del log (es. nome del modulo o funzione).
40+
* @param {string|Error|Object} message - Messaggio da loggare (stringa, errore o JSON).
41+
* @param {string|null} [subContext=null] - Contesto secondario opzionale.
42+
* @param {Function|null} [messageColor=null] - Colore personalizzato per il messaggio (opzionale).
43+
*/
44+
declare const logMessage: (level: LogLevel, context: string, message: unknown, subContext?: string | null, messageColor?: ColorFn | null) => void;
45+
/**
46+
* Funzione per logging degli errori.
47+
*/
48+
declare const logError: (context: string, error: unknown, subContext?: string, messageColor?: ColorFn | null) => void;
49+
/**
50+
* Funzione per logging dei warning.
51+
*/
52+
declare const logWarn: (context: string, message: unknown, subContext?: string, messageColor?: ColorFn | null) => void;
53+
/**
54+
* Funzione per logging informativo.
55+
*/
56+
declare const logInfo: (context: string, message: unknown, subContext?: string, messageColor?: ColorFn | null) => void;
57+
/**
58+
* Funzione per logging di debug.
59+
*/
60+
declare const logDebug: (context: string, message: unknown, subContext?: string, messageColor?: ColorFn | null) => void;
61+
/**
62+
* Logger centralizzato per il debug delle informazioni utente e degli aggiornamenti del database.
63+
*
64+
* @param {string} label - Etichetta per il log (es. "Matched Servers JSON" o "mainPrisma User Updated result").
65+
* @param {string} context - Contesto del log (es. "handleAuthentication").
66+
* @param {string} fusername - Nome utente in fase di autenticazione.
67+
* @param {Object} data - Dati da loggare (es. `matchedServers` o `updatedMainPrisma`).
68+
* @param {number} verbosityLevel - Livello di verbosità richiesto per il log.
69+
* @param {number} requiredVerbosity - Livello minimo di verbosità per stampare il log.
70+
* @param {Function|null} [messageColor=null] - Colore personalizzato per il messaggio (opzionale).
71+
*
72+
* @example
73+
* // Log dei server associati
74+
* logDebugData(
75+
* 'Matched Servers JSON',
76+
* 'handleAuthentication',
77+
* fusername,
78+
* matchedServers,
79+
* AUTH_VERBOSITY,
80+
* 1,
81+
* color.cyan
82+
* );
83+
*/
84+
declare const logDebugData: (label: string, context: string, fusername: string, data: Record<string, any>, verbosityLevel: number, requiredVerbosity: number, messageColor?: ColorFn | null) => void;
85+
/**
86+
* Recupera il nome della prima funzione chiamante esterna significativa,
87+
* saltando frame interni e quelli anonimi.
88+
*
89+
* @returns {string} - Nome della funzione chiamante o 'anonymous' se non identificabile.
90+
*/
91+
declare const getFunctionName: () => string;
92+
export { color, log, whiteBG, bgWhite, bgYellowBright, bgCyanBright, cyanBright, whiteBright, white, blueBright, red, green, cyan, yellow, magenta, usage, colorizeKeysAsString, colorizeKeysAsStringIndent, logError, logDebug, logInfo, logMessage, logWarn, logDebugData, getFunctionName };

0 commit comments

Comments
 (0)