@fonoster/logger 0.8.59 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/envs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import winston from "winston";
2
- declare const LOGS_LEVEL: string;
2
+ declare const LOGS_LEVEL: any;
3
3
  declare const fluent: any;
4
4
  declare const format: winston.Logform.Format;
5
5
  declare const transports: any[];
package/dist/envs.js CHANGED
@@ -24,14 +24,16 @@ exports.transports = exports.level = exports.format = exports.fluent = void 0;
24
24
  */
25
25
  const fluent_logger_1 = __importDefault(require("fluent-logger"));
26
26
  const winston_1 = __importDefault(require("winston"));
27
+ const getEnv_1 = require("./getEnv");
27
28
  const FluentTransport = fluent_logger_1.default.support.winstonTransport();
28
- const LOGS_DRIVER_HOST = process.env.LOGS_DRIVER_HOST;
29
- const LOGS_DRIVER_PORT = process.env.LOGS_DRIVER_PORT || 24224;
30
- const LOGS_OPT_TAG_PREFIX = process.env.LOGS_OPT_TAG_PREFIX || "fonoster-logs";
31
- const LOGS_FORMAT = process.env.LOGS_FORMAT || "json";
32
- const LOGS_LEVEL = process.env.LOGS_LEVEL || "info";
29
+ const LOGS_DRIVER_HOST = (0, getEnv_1.getEnv)("LOGS_DRIVER_HOST");
30
+ // Note: if LOGS_DRIVER_PORT is provided as a string in the environment, it will be used as-is.
31
+ const LOGS_DRIVER_PORT = (0, getEnv_1.getEnv)("LOGS_DRIVER_PORT", 24224);
32
+ const LOGS_OPT_TAG_PREFIX = (0, getEnv_1.getEnv)("LOGS_OPT_TAG_PREFIX", "fonoster-logs");
33
+ const LOGS_FORMAT = (0, getEnv_1.getEnv)("LOGS_FORMAT", "json");
34
+ const LOGS_LEVEL = (0, getEnv_1.getEnv)("LOGS_LEVEL", "info");
33
35
  exports.level = LOGS_LEVEL;
34
- const LOGS_TRANSPORT = process.env.LOGS_TRANSPORT || "console";
36
+ const LOGS_TRANSPORT = (0, getEnv_1.getEnv)("LOGS_TRANSPORT", "console");
35
37
  const fluent = new FluentTransport(`${LOGS_OPT_TAG_PREFIX}`, {
36
38
  host: LOGS_DRIVER_HOST,
37
39
  port: LOGS_DRIVER_PORT,
@@ -0,0 +1,2 @@
1
+ declare function getEnv(key: string, defaultValue?: any): any;
2
+ export { getEnv };
package/dist/getEnv.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
4
+ * http://github.com/fonoster/fonoster
5
+ *
6
+ * This file is part of Fonoster
7
+ *
8
+ * Licensed under the MIT License (the "License");
9
+ * you may not use this file except in compliance with
10
+ * the License. You may obtain a copy of the License at
11
+ *
12
+ * https://opensource.org/licenses/MIT
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.getEnv = getEnv;
22
+ // Add a helper function that will check for a service-prefixed environment variable
23
+ // For example, for key "LOGS_FORMAT" it will return process.env.APISERVER_LOGS_FORMAT if exists,
24
+ // and fall back to process.env.LOGS_FORMAT otherwise.
25
+ function getEnv(key, defaultValue) {
26
+ // Look for any environment variable that is a service-prefixed variable (e.g. APISERVER_LOGS_FORMAT)
27
+ const prefixedKey = Object.keys(process.env).find(envKey => envKey !== key && envKey.endsWith(`_${key}`));
28
+ if (prefixedKey !== undefined && process.env[prefixedKey] !== undefined) {
29
+ return process.env[prefixedKey];
30
+ }
31
+ return process.env[key] !== undefined ? process.env[key] : defaultValue;
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/logger",
3
- "version": "0.8.59",
3
+ "version": "0.9.7",
4
4
  "description": "Logger module",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -32,5 +32,5 @@
32
32
  "fluent-logger": "^3.4.1",
33
33
  "winston": "^3.13.0"
34
34
  },
35
- "gitHead": "6a5255febb9e4bcd9184d93abe72281f945c8c4d"
35
+ "gitHead": "58373b604b2e29bcfc6b88a2f30ae45afb4e97a7"
36
36
  }