mirror of
https://github.com/fergalmoran/radio-otherway.git
synced 2025-12-22 09:50:29 +00:00
Add notification & scheduling callbacks
This commit is contained in:
@@ -1,24 +1,72 @@
|
||||
import pino from 'pino'
|
||||
import {logflarePinoVercel} from 'pino-logflare'
|
||||
const logger = (() => {
|
||||
const checkIfLogsEnabled = () => {
|
||||
if (process.browser) {
|
||||
const search = global?.window?.location?.search;
|
||||
const enabled =
|
||||
search && new URLSearchParams(search).get("debug") === "true";
|
||||
|
||||
const {stream, send} = logflarePinoVercel({
|
||||
apiKey: "MK3qgU_-pwHQ",
|
||||
sourceToken: "f7d8c11d-8f36-4981-8168-bfd69aa72bbf"
|
||||
});
|
||||
|
||||
// create pino logger
|
||||
const logger = pino({
|
||||
browser: {
|
||||
transmit: {
|
||||
level: "info",
|
||||
send: send,
|
||||
global.areLogsEnabled = enabled || false;
|
||||
return global.areLogsEnabled;
|
||||
}
|
||||
},
|
||||
level: "debug",
|
||||
base: {
|
||||
env: process.env.NODE_ENV,
|
||||
revision: process.env.VERCEL_GITHUB_COMMIT_SHA,
|
||||
},
|
||||
}, stream);
|
||||
|
||||
export default logger
|
||||
return false;
|
||||
};
|
||||
|
||||
const isDev = process.env.NODE_ENV !== "production";
|
||||
|
||||
const print = (type, ...messages) => {
|
||||
if (typeof global.areLogsEnabled === "undefined") {
|
||||
checkIfLogsEnabled();
|
||||
}
|
||||
|
||||
if (global.areLogsEnabled || isDev) {
|
||||
switch (type) {
|
||||
case "info":
|
||||
console.info(
|
||||
"%c Custom Log:",
|
||||
"background: blue; color: white;",
|
||||
...messages
|
||||
);
|
||||
break;
|
||||
case "warn":
|
||||
console.warn(
|
||||
"%c Custom Log:",
|
||||
"background: orange; color: white;",
|
||||
...messages
|
||||
);
|
||||
break;
|
||||
case "error":
|
||||
console.error(
|
||||
"%c Custom Log:",
|
||||
"background: red; color: white;",
|
||||
...messages
|
||||
);
|
||||
break;
|
||||
case "trace":
|
||||
console.trace(
|
||||
"%c Custom Log:",
|
||||
"background: grey; color: black;",
|
||||
...messages
|
||||
);
|
||||
break;
|
||||
case "debug":
|
||||
default:
|
||||
console.log(
|
||||
"%c Custom Log:",
|
||||
"background: green; color: white;",
|
||||
...messages
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
debug: print.bind(null, "debug"),
|
||||
info: print.bind(null, "info"),
|
||||
warn: print.bind(null, "warn"),
|
||||
error: print.bind(null, "error"),
|
||||
trace: print.bind(null, "trace"),
|
||||
};
|
||||
})();
|
||||
|
||||
export default logger;
|
||||
|
||||
Reference in New Issue
Block a user