UNPKG

reactotron-core-client

Version:

Grants Reactotron clients the ability to talk to a Reactotron server.

54 lines (53 loc) 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hasLoggerPlugin = exports.default = exports.assertHasLoggerPlugin = void 0; /** * Provides 4 features for logging. log & debug are the same. */ const logger = () => reactotron => { return { features: { log: (...args) => { const content = args && args.length === 1 ? args[0] : args; reactotron.send("log", { level: "debug", message: content }, false); }, logImportant: (...args) => { const content = args && args.length === 1 ? args[0] : args; reactotron.send("log", { level: "debug", message: content }, true); }, debug: (message, important = false) => reactotron.send("log", { level: "debug", message }, !!important), warn: message => reactotron.send("log", { level: "warn", message }, true), error: (message, stack) => reactotron.send("log", { level: "error", message, stack }, true) } }; }; var _default = exports.default = logger; const hasLoggerPlugin = reactotron => { return reactotron && "log" in reactotron && typeof reactotron.log === "function" && "logImportant" in reactotron && typeof reactotron.logImportant === "function" && "debug" in reactotron && typeof reactotron.debug === "function" && "warn" in reactotron && typeof reactotron.warn === "function" && "error" in reactotron && typeof reactotron.error === "function"; }; exports.hasLoggerPlugin = hasLoggerPlugin; const assertHasLoggerPlugin = reactotron => { if (!hasLoggerPlugin(reactotron)) { throw new Error("This Reactotron client has not had the logger plugin applied to it. Make sure that you add `use(logger())` before adding this plugin."); } }; exports.assertHasLoggerPlugin = assertHasLoggerPlugin; //# sourceMappingURL=logger.js.map