當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Logger.Logger類代碼示例

本文整理匯總了TypeScript中common/Logger.Logger的典型用法代碼示例。如果您正苦於以下問題:TypeScript Logger類的具體用法?TypeScript Logger怎麽用?TypeScript Logger使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Logger類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: onMessage

 private onMessage(logger: Logger, msg: ISM) {
   if (msg.type === "no-update-available") {
     this.stage("idle");
   } else if (msg.type === "installing-update") {
     this.stage("download");
   } else if (msg.type === "update-failed") {
     const pp = msg.payload as ISM_UpdateFailed;
     logger.error(`Self-update failed: ${pp.message}`);
   } else if (msg.type === "update-ready") {
     const pp = msg.payload as ISM_UpdateReady;
     logger.info(`Version ${pp.version} is ready to be used.`);
     this.store.dispatch(
       actions.packageNeedRestart({
         name: this.name,
         availableVersion: pp.version,
       })
     );
   } else if (msg.type === "progress") {
     const pp = msg.payload as ISM_Progress;
     this.store.dispatch(
       actions.packageProgress({
         name: this.name,
         progressInfo: pp,
       })
     );
   } else if (msg.type === "log") {
     const pp = msg.payload as ISM_Log;
     logger.info(`> ${pp.message}`);
   }
 }
開發者ID:itchio,項目名稱:itch,代碼行數:30,代碼來源:self-package.ts

示例2: downloadToFileWithRetry

export async function downloadToFileWithRetry(
  onProgress: (progress: ProgressInfo) => void,
  logger: Logger,
  url: string,
  file: string
) {
  let tries = 0;
  const maxTries = 8;

  let lastError: Error;
  while (tries < maxTries) {
    if (tries > 0) {
      logger.warn(`Downloading file, try ${tries}`);
    }

    try {
      await downloadToFile(onProgress, logger, url, file);
    } catch (originalErr) {
      let err = originalErr as HTTPError;
      if (err.httpStatusCode) {
        let shouldRetry = false;
        if (httpStatusesThatWarrantARetry.indexOf(err.httpStatusCode)) {
          shouldRetry = true;
        }

        if (shouldRetry) {
          lastError = originalErr;
          tries++;
          // exponential backoff: 1, 2, 4, 8 seconds...
          let numSeconds = tries * tries;
          // ...plus a random number of milliseconds.
          // see https://cloud.google.com/storage/docs/exponential-backoff
          let jitter = Math.random() % 1000;
          let sleepTime = numSeconds * 1000 + jitter;
          logger.warn(`While downloading file, got: ${err.stack}`);
          logger.warn(`Retrying after ${sleepTime.toFixed()}ms`);
          await delay(sleepTime);
          tries++;
          continue;
        }
      }
      throw originalErr;
    }
    return;
  }

  logger.warn(`${tries} failed, returning error.`);
  throw lastError;
}
開發者ID:itchio,項目名稱:itch,代碼行數:49,代碼來源:download.ts

示例3: err

function err(logger: Logger, e: Error, action: Action<any>) {
  if (isCancelled(e)) {
    console.warn(`reactor for ${action.type} was cancelled`);
  } else {
    const actionName = (action || { type: "?" }).type;
    const errorStack = e.stack || e;
    const msg = `while reacting to ${actionName}: ${errorStack}`;
    logger.error(msg);
  }
}
開發者ID:itchio,項目名稱:itch,代碼行數:10,代碼來源:route.ts

示例4: async

 client.on(messages.LaunchWindowShouldBeForeground, async ({ hwnd }) => {
   try {
     require("asfw").SetForegroundWindow(hwnd);
   } catch (e) {
     logger.warn(`Could not set foreground window: ${e.stack}`);
   }
 });
開發者ID:HorrerGames,項目名稱:itch,代碼行數:7,代碼來源:perform-launch.ts

示例5: setImmediate

 setImmediate(() => {
   try {
     f();
   } catch (e) {
     this.logger.error(`In scheduled stateChange: ${e.stack}`);
   }
 });
開發者ID:itchio,項目名稱:itch,代碼行數:7,代碼來源:watcher.ts

示例6: async

    this.addWatcher(actionName, async (store, action) => {
      let rs = store.getState();
      if (rs === oldRs) {
        return;
      }
      oldRs = rs;

      if (!selector) {
        const schedule: Schedule = f => {
          setImmediate(() => {
            try {
              f();
            } catch (e) {
              this.logger.error(`In scheduled stateChange: ${e.stack}`);
            }
          });
        };
        schedule.dispatch = (action: Action<any>) => {
          schedule(() => store.dispatch(action));
        };
        selector = makeSelector(store, schedule);
      }

      try {
        selector(rs);
      } catch (e) {
        this.logger.error(`In state selector: ${e.stack}`);
      }
    });
開發者ID:itchio,項目名稱:itch,代碼行數:29,代碼來源:watcher.ts

示例7: async

 convo.on(messages.Log, async ({ level, message }) => {
   switch (level) {
     case "debug":
       logger.debug(message);
       break;
     case "info":
       logger.info(message);
       break;
     case "warning":
       logger.warn(message);
       break;
     case "error":
       logger.error(message);
       break;
     default:
       logger.info(`[${level}] ${message}`);
       break;
   }
 });
開發者ID:itchio,項目名稱:itch,代碼行數:19,代碼來源:utils.ts

示例8: Error

      cb: res => {
        logger.info(`HTTP ${res.statusCode} ${url}`);
        if (!/^2/.test("" + res.statusCode)) {
          throw new Error(`HTTP ${res.statusCode} ${url}`);
        }

        const contentLengthHeader = res.headers["content-length"];
        if (!isEmpty(contentLengthHeader)) {
          totalSize = parseInt(contentLengthHeader[0], 10);
        }
      },
開發者ID:HorrerGames,項目名稱:itch,代碼行數:11,代碼來源:download.ts


注:本文中的common/Logger.Logger類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。