Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungThe Model Got Better. Your Judgment Got Worse.(22.09.2026 um 03:02 Uhr)
Sichere ProgrammierungAIFeed - signed content permissions for AI web crawlers(22.09.2026 um 03:10 Uhr)
Sichere ProgrammierungThanks, glad you liked it!(22.09.2026 um 03:15 Uhr)
Sichere ProgrammierungA request for /.env shouldn't render your React app(22.09.2026 um 03:17 Uhr)
Sichere ProgrammierungAI-Agent Marketplaces Need Verifiable Delivery, Not More Listings(22.09.2026 um 03:20 Uhr)
AI & KI NachrichtenBeyond Bigger Models: Toward a Modular Cognitive Architecture(22.09.2026 um 03:21 Uhr)
Sichere ProgrammierungMasa Depan Manajemen Data: Mengenal Konsep Data Mesh yang Revolusioner(22.09.2026 um 03:22 Uhr)
Sichere ProgrammierungHow to Search Your Claude Code Conversation History(22.09.2026 um 03:22 Uhr)
Sichere ProgrammierungThe Model Got Better. Your Judgment Got Worse.(22.09.2026 um 03:02 Uhr)
Sichere ProgrammierungAIFeed - signed content permissions for AI web crawlers(22.09.2026 um 03:10 Uhr)
Sichere ProgrammierungThanks, glad you liked it!(22.09.2026 um 03:15 Uhr)
Sichere ProgrammierungA request for /.env shouldn't render your React app(22.09.2026 um 03:17 Uhr)
Sichere ProgrammierungAI-Agent Marketplaces Need Verifiable Delivery, Not More Listings(22.09.2026 um 03:20 Uhr)
AI & KI NachrichtenBeyond Bigger Models: Toward a Modular Cognitive Architecture(22.09.2026 um 03:21 Uhr)
Sichere ProgrammierungMasa Depan Manajemen Data: Mengenal Konsep Data Mesh yang Revolusioner(22.09.2026 um 03:22 Uhr)
Sichere ProgrammierungHow to Search Your Claude Code Conversation History(22.09.2026 um 03:22 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

[At Run Time] Adaptative Log Function

When debugging some buge coding project, you want sometimes to drop a console.log() calls to track some varaible and errors, to figure out what is happening during program execution, especially nearby potential tricky sections of it;…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

When debugging some buge coding project, you want sometimes to drop a console.log() calls to track some varaible and errors, to figure out what is happening during program execution, especially nearby potential tricky sections of it; something like:




function danger (a: number, b: number) {
console.log ('### (title "h3") the dangerous function is here...')

try {
return a / b
} catch (err) {
console.log ('posssible divisoion by zero !')
console.log ({a, b })

throw new Error ('#DIVIDE_BY_ZERO')
}
}




This approach gives you the ability to see the error at its location.



But the more code grows and the more logging calls occurrences grows together... and when comes And that produces time-consuming task to remove these calls (manually or not): lot of work in perpsective, and risks to waste time introducing some garbage (characters typos) and need to fix it again.






Logger class (first idea)



The idea for now is to add a Logger/Debugger class to filter console.log calls and shutdown its messages when the production phase comes.




function danger (a: number, b: number) {
const debug = Debug.getInstance ()

debug.level (3).title ('the dangerous function is here...')

try {
return a / b
} catch (err) {
debug.level (2).title ('posssible divisoion by zero !')
debug.level (3).dump ({a, b })

throw new Error ('#DIVIDE_BY_ZERO')
}
}




Note: the singelton instance exposes a level method that returns a fluent interface, backed by some closure and bounding pattern, and wrap console.log calls:




// Debug class
protected verbosity = 0

protected log (effective: number, something) {
if (this.verbosity < effective ) {
// here we effectively log in the browser
console.log (something)
}
}

protected title (level: number, text: string) {
const message = '#'.repat (level) + ' ' + text
this.log (level, message)
}

protected dump (level: number,something) {
this.log (level, something)
}

public level (wandered: number) {
return {
title: this.title.bind (this, this.verbosiry),
dump: this.dump.bind (this, this.verbosiry),
}
}




No it's OK logginh process is filterd properly. Adapt it now ?






Adaptative ? OK for now !



Declare a setter for thos.verbosity value:





// default behaviour:  shutdown all logs (silent)

public adapt (wantered: number = 0) {

this.verbosity = wandered

}











USE CASE: dangerous functions




  • Phase of self-tests of program: log enough stuff;

  • Phase Produiction: log normally and minimally (0: silently, when possible);


  • Increase drastrically verbosity just before throwing errors:



    function danger (a: number, b: number) {

    const debug = Debug.getInstance ()


    debug.level (3).title ('the dangerous function is here...')

    try {
    return a / b
    } catch (err) {
    // now we have all errors log:
    debug.adapt (10)
    debug.level (2).title ('posssible divisoion by zero !')
    debug.level (3).dump ({a, b })

    throw new Error ('#DIVIDE_BY_ZERO')
    }

    }



    function process (iterations: number) {

    const debug = Debug.getInstance ()


    for (let a = 0; a < iterations; a++) {
    for (let b = 0; b < iterations; b++) {}
    // print all results
    // debug.level (0).dump (danger (a,b ))

    // or log anyway, print, do whatever with results...
    console.log (danger (an b))
    }

    }



    // *** caller code (main routine) ***

    const debug = Debug.getInstance ()



    // self tests

    debug.adapt (1)

    process (1)



    // produiuction phase: NO MPGS

    debug.adapt (0)

    process (1000 * 1000)





Doing like this, we adapt the logging mechanism to see clearly what is happening diring tests phase and after dangerous runtime error occurrence, the rest of (normal) run time we don't pollute the briwser's console anymore, neither altering performances anymore.



Happy coding !

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten [At Run Time] Adaptative Log Function

Thematisch verwandte Begriffe: Time, Adaptative, Function · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-49449 | Joplin is an open source note-taking and to-do application that organise…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick