message: fix(server): don't output all log messages
diff: @@ -51,18 +51,59 @@ function makeLogMessage(level: LevelPrefix, callsite: Callsite, message: string)
  )}:${callsite.getLineNumber()}] ${message}`;
  }
  +export enum LogLevel {
  + // The order here is important, from less to more verbose.
  + ERROR,
  + WARNING,
  + INFO,
  + DEBUG,
  +}
  +
  +const maxMsgLevel = logLevelFromEnvironment();
  +
  +function logLevelFromEnvironment(): LogLevel {
  + if (process.env.LOG_LEVEL) {
  + return parseLogLevel(process.env.LOG_LEVEL);
  + }
  + return LogLevel.INFO;
  +}
  +
  +function parseLogLevel(levelStr: string) {
  + switch(levelStr.toLowerCase()) {
  + case "error":
  + return LogLevel.ERROR;
  + case "warning":
  + case "warn":
  + return LogLevel.WARNING;
  + case "info":
  + return LogLevel.INFO;
  + case "debug":
  + return LogLevel.DEBUG;
  + default:
  + throw new Error(`Invalid log level "${levelStr}"`);
  + }
  +}
  +
  export function error(message: string) {
  + if (LogLevel.ERROR <= maxMsgLevel) {
  console.error(makeLogMessage('E', getCallsite(), message));
  }
  +}
  export function warn(message: string) {
  + if (LogLevel.WARNING <= maxMsgLevel) {
  console.warn(makeLogMessage('W', getCallsite(), message));
  }
  +}
  export function info(message: string) {
  + if (LogLevel.INFO <= maxMsgLevel) {
  console.info(makeLogMessage('I', getCallsite(), message));
  }
  +}
  export function debug(message: string) {
  + if (LogLevel.DEBUG <= maxMsgLevel) {
  console.debug(makeLogMessage('D', getCallsite(), message));
  }
  +}
  