From 6964faf8f43d959e32e3a8fb994c709bcb90034b Mon Sep 17 00:00:00 2001 From: realaravinth Date: Mon, 3 May 2021 23:16:00 +0530 Subject: [PATCH] logger --- templates/env.ts | 23 +++++++++++++++++++++++ templates/logger.ts | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 templates/env.ts create mode 100644 templates/logger.ts diff --git a/templates/env.ts b/templates/env.ts new file mode 100644 index 00000000..a40ade11 --- /dev/null +++ b/templates/env.ts @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 Aravinth Manivannan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +export enum MODE { + production, + development, +} + +export const mode = MODE.development; diff --git a/templates/logger.ts b/templates/logger.ts new file mode 100644 index 00000000..499ff6f2 --- /dev/null +++ b/templates/logger.ts @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Aravinth Manivannan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import {mode, MODE} from './env'; + +/** Conditional logger singleton */ +export const log = (function() { + return { + /** get levels */ + debug: (data: any) => { + if (mode == MODE.development) { + console.debug(data); + } + }, + + error: (data: any) => { + console.error(data); + }, + + log: (data: any) => { + console.log(data); + }, + }; +})();