Closed bryanbecker closed 7 years ago
Not sure if this is what you're looking for, but I usually add the following to my config.ts
so that I can have better control of my log levels:
// ./config/config.ts
export const ENABLE_DEBUG_MODE: boolean = false;
// ./main.ts
export function loop() {
if (Config.ENABLE_DEBUG_MODE) {
log.debug("Game loop started");
}
// ...
}
You might also be able to pass a NODE_ENV
variable while you compile your code. A package like cross-env is a good cross-platform solution.
I think you can can achieve what you posted above easier, and with less calls by just setting
// ./config/config.ts
export const LOG_LEVEL: number = LogLevels.DEBUG; // or ERROR, WARNING, INFO
Then you don't need to check if (Config.ENABLE_DEBUG_MODE)
since the included log module does that for you. (i.e. if you set LOG_LEVEL
to WARNING
, then places in your code callign log.debug
won't output)
What I was hoping for was a way to modify LOG_LEVEL
based on the target. For example, npm run prod
would set LOG_LEVEL to ERROR, while npm run dev
would set it to DEBUG
You could look at how LOG_VSC variable is set and do something like that for LOG_LEVEL. Look for @@_repo_@@
in gulpfile.
I find it is more useful to modify log level at runtime (using log.level =
in console) though, because I have way too much spam at debug level. :)
I find it is more useful to modify log level at runtime (using log.level = in console)
I don't know why I didn't think of that :man_facepalming: ... that's way more convenient than mucking around with gulp
I'm going to close this, as the above solution works just fine
It would be nice to be able to conditionally set variables based on build environment.
I can think of a couple hypothetical ways to accomplish this:
Config
not be typescript, but instead POJS (this may get around above)