Static & Private Class Fields
What pattern is demonstrated with static private members?
class Logger {
static #logLevel = 'info';
static {
try {
this.#logLevel = process.env.LOG_LEVEL || this.#logLevel;
} catch {
// Keep default
}
}
static #formatMessage(level, msg) {
return `[${level.toUpperCase()}] ${msg}`;
}
static log(msg) {
console.log(this.#formatMessage(this.#logLevel, msg));
}
}