mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Logging: add frontend logging helpers to @grafana/runtime package (#30482)
This commit is contained in:
parent
9ce07b11d2
commit
3bc9f78d76
@ -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';
|
||||
|
50
packages/grafana-runtime/src/utils/logging.ts
Normal file
50
packages/grafana-runtime/src/utils/logging.ts
Normal 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 });
|
||||
}
|
Loading…
Reference in New Issue
Block a user