mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove all usages of legacy global logger
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
1456e1e597
commit
ade0775061
107 files changed
+852
-606
No files matched your search
@@ -3,6 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
import clusterFrameContextForNamespacedResourcesInjectable from "../cluster-frame-context/for-namespaced-resources.injectable";
|
||||
import { KubeWatchApi } from "./kube-watch-api";
|
||||
|
||||
@@ -11,6 +12,7 @@ const kubeWatchApiInjectable = getInjectable({
|
||||
|
||||
instantiate: (di) => new KubeWatchApi({
|
||||
clusterContext: di.inject(clusterFrameContextForNamespacedResourcesInjectable),
|
||||
logger: di.inject(loggerInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { comparer, reaction } from "mobx";
|
||||
import type { Disposer } from "../../common/utils";
|
||||
import { disposer, getOrInsert, noop, WrappedAbortController } from "../../common/utils";
|
||||
import { once } from "lodash";
|
||||
import logger from "../../common/logger";
|
||||
import type { Logger } from "../../common/logger";
|
||||
import type { KubeObjectStoreLoadAllParams, KubeObjectStoreSubscribeParams } from "../../common/k8s-api/kube-object.store";
|
||||
import AbortController from "abort-controller";
|
||||
import type { ClusterContext } from "../cluster-frame-context/cluster-frame-context";
|
||||
@@ -21,13 +21,19 @@ interface SubscribeStoreParams {
|
||||
onLoadFailure?: (err: any) => void;
|
||||
}
|
||||
|
||||
interface WatchCountDependencies {
|
||||
readonly logger: Logger;
|
||||
}
|
||||
|
||||
class WatchCount {
|
||||
readonly #data = new Map<SubscribableStore, number>();
|
||||
|
||||
constructor(private readonly dependencies: WatchCountDependencies) {}
|
||||
|
||||
public inc(store: SubscribableStore): number {
|
||||
const newCount = getOrInsert(this.#data, store, 0) + 1;
|
||||
|
||||
logger.info(`[KUBE-WATCH-API]: inc() count for ${store.api.apiBase} is now ${newCount}`);
|
||||
this.dependencies.logger.info(`[KUBE-WATCH-API]: inc() count for ${store.api.apiBase} is now ${newCount}`);
|
||||
this.#data.set(store, newCount);
|
||||
|
||||
return newCount;
|
||||
@@ -46,7 +52,7 @@ class WatchCount {
|
||||
throw new Error(`Cannot dec count more times than it has been inc: ${store.api.kind}`);
|
||||
}
|
||||
|
||||
logger.info(`[KUBE-WATCH-API]: dec() count for ${store.api.apiBase} is now ${newCount}`);
|
||||
this.dependencies.logger.info(`[KUBE-WATCH-API]: dec() count for ${store.api.apiBase} is now ${newCount}`);
|
||||
this.#data.set(store, newCount);
|
||||
|
||||
return newCount;
|
||||
@@ -69,6 +75,7 @@ export interface KubeWatchSubscribeStoreOptions {
|
||||
|
||||
interface Dependencies {
|
||||
readonly clusterContext: ClusterContext;
|
||||
readonly logger: Logger;
|
||||
}
|
||||
|
||||
export interface SubscribableStore {
|
||||
@@ -84,7 +91,7 @@ export interface SubscribableStore {
|
||||
export type SubscribeStores = (stores: SubscribableStore[], opts?: KubeWatchSubscribeStoreOptions) => Disposer;
|
||||
|
||||
export class KubeWatchApi {
|
||||
readonly #watch = new WatchCount();
|
||||
readonly #watch = new WatchCount(this.dependencies);
|
||||
|
||||
constructor(private readonly dependencies: Dependencies) {}
|
||||
|
||||
@@ -173,8 +180,8 @@ export class KubeWatchApi {
|
||||
|
||||
protected log(message: any, meta: any) {
|
||||
const log = message instanceof Error
|
||||
? console.error
|
||||
: console.debug;
|
||||
? this.dependencies.logger.error
|
||||
: this.dependencies.logger.debug;
|
||||
|
||||
log("[KUBE-WATCH-API]:", message, {
|
||||
time: new Date().toLocaleString(),
|
||||
|
||||
Reference in new issue
Block a user