Logging: add frontend logging helpers to @grafana/runtime package (#30482)

This commit is contained in:
Domas 2021-02-23 13:02:45 +02:00 committed by GitHub
parent 9ce07b11d2
commit 3bc9f78d76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View File

@ -9,5 +9,6 @@ export * from './types';
export * from './measurement';
export { loadPluginCss, SystemJS, PluginCssOptions } from './utils/plugin';
export { reportMetaAnalytics } from './utils/analytics';
export { logInfo, logDebug, logWarning, logError } from './utils/logging';
export { DataSourceWithBackend, HealthCheckResult, HealthStatus } from './utils/DataSourceWithBackend';
export { toDataQueryError, toDataQueryResponse, frameToMetricFindValue } from './utils/queryResponse';

View File

@ -0,0 +1,50 @@
import { captureMessage, captureException, Severity as LogLevel } from '@sentry/browser';
export { LogLevel };
// a bit stricter than what Sentry allows
type Contexts = Record<string, Record<string, number | string | Record<string, string | number>>>;
/**
* Log a message at INFO level. Depending on configuration might be forwarded to backend and logged to stdout or sent to Sentry
*
* @public
*/
export function logInfo(message: string, contexts?: Contexts) {
captureMessage(message, {
level: LogLevel.Info,
contexts,
});
}
/**
* Log a message at WARNING level. Depending on configuration might be forwarded to backend and logged to stdout or sent to Sentry
*
* @public
*/
export function logWarning(message: string, contexts?: Contexts) {
captureMessage(message, {
level: LogLevel.Warning,
contexts,
});
}
/**
* Log a message at DEBUG level. Depending on configuration might be forwarded to backend and logged to stdout or sent to Sentry
*
* @public
*/
export function logDebug(message: string, contexts?: Contexts) {
captureMessage(message, {
level: LogLevel.Debug,
contexts,
});
}
/**
* Log an error. Depending on configuration might be forwarded to backend and logged to stdout or sent to Sentry
*
* @public
*/
export function logError(err: Error, contexts?: Contexts) {
captureException(err, { contexts });
}