summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2021-09-09 21:43:32 -0700
committerMatthew Miller <matthew@millerti.me>2021-09-09 21:46:15 -0700
commit6e87a5cce786b04b122dd151e809e206fc8f702e (patch)
tree71c78d7bf2d5e8701db180575ca9ac1ace07b7fc
parent6590b4c1722bb36617c4e76772fa385d53fd0eb3 (diff)
Create method to spawn namespaced loggers
-rw-r--r--packages/server/src/helpers/logging.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/server/src/helpers/logging.ts b/packages/server/src/helpers/logging.ts
new file mode 100644
index 0000000..2a8b67e
--- /dev/null
+++ b/packages/server/src/helpers/logging.ts
@@ -0,0 +1,21 @@
+import debug, { Debugger } from 'debug';
+
+const defaultLogger = debug('SimpleWebAuthn');
+
+/**
+ * Generate an instance of a `debug` logger that extends off of the "simplewebauthn" namespace for
+ * consistent naming.
+ *
+ * See https://www.npmjs.com/package/debug for information on how to control logging output when
+ * using @simplewebauthn/server
+ *
+ * Example:
+ *
+ * ```
+ * const log = getLogger('mds');
+ * log('hello'); // simplewebauthn:mds hello +0ms
+ * ```
+ */
+export function getLogger(name: string): Debugger {
+ return defaultLogger.extend(name);
+}