本文整理匯總了TypeScript中common/Logger.Logger.warn方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Logger.warn方法的具體用法?TypeScript Logger.warn怎麽用?TypeScript Logger.warn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類common/Logger.Logger
的用法示例。
在下文中一共展示了Logger.warn方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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;
}
示例2: async
client.on(messages.LaunchWindowShouldBeForeground, async ({ hwnd }) => {
try {
require("asfw").SetForegroundWindow(hwnd);
} catch (e) {
logger.warn(`Could not set foreground window: ${e.stack}`);
}
});
示例3: 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;
}
});
示例4: getClient
async function getClient(store: Store, parentLogger: Logger): Promise<Client> {
let p: ClientPromise;
if (clientPromises.has(store)) {
p = clientPromises.get(store);
} else {
p = makeClient(store, parentLogger);
clientPromises.set(store, p);
}
const client = await p;
const currentEndpoint = store.getState().butlerd.endpoint;
if (client.endpoint !== currentEndpoint) {
parentLogger.warn(
`(butlerd) Endpoint changed (${client.endpoint.tcp.address} => ${
currentEndpoint.tcp.address
}), making fresh client`
);
p = makeClient(store, parentLogger);
clientPromises.set(store, p);
}
return p;
}