akamai-edgegrid 3.5.6 → 4.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Release notes
2
2
 
3
+ ## 4.0.1 (Mar 4, 2026)
4
+
5
+ ### Features/Enhancements
6
+
7
+ * Updated various dependencies.
8
+
9
+ ## 4.0.0 (Dec 4, 2025)
10
+
11
+ ### Breaking Changes
12
+
13
+ * Replaced `log4js` with `pino` for logging and removed the `log4js` dependency.
14
+ * Updated logging configuration with the following environment variables:
15
+ * `AKAMAI_LOG_LEVEL` - controls log severity. Possible values are: `fatal`, `error`, `warn`, `info`, `debug`, or `trace`. Defaults to `info`.
16
+ * `AKAMAI_LOG_PRETTY` - enables pretty-printed, human-readable log format when set to `true`. Defaults to `false`.
17
+ * Logging is now disabled by default, ensuring zero logging unless explicitly enabled.
18
+ * Introduced the `enableLogging(option)` function to programmatically control logging:
19
+ * Passing `true` enables logging based on environment variables.
20
+ * Passing a valid "pino-like" logger object sets the current logger. Custom loggers must implement the `info`, `debug`, `error`, and `warn` methods.
21
+ * Exported `enableLogging` for external use, replacing the previous default `logger` export.
22
+ * Removed support for the `EG_VERBOSE` environment variable; Axios interceptors now always log at the `debug` level.
23
+ * Removed support for the `debug` parameter from the EdgeGrid constructor; debugging is now fully managed through `enableLogging()`.
24
+
25
+ ### Features/Enhancements
26
+
27
+ * Updated various dependencies.
28
+
3
29
  ## 3.5.6 (Oct 15, 2025)
4
30
 
5
31
  ### Bug fixes
@@ -11,7 +37,7 @@
11
37
  ### Features/Enhancements
12
38
 
13
39
  * Updated various dependencies.
14
- * Removed support for Node.js versions 18, 21 and 23.
40
+ * Removed support for Node.js versions 18, 21, and 23.
15
41
 
16
42
  ## 3.5.4 (Jul 24, 2025)
17
43
 
package/LICENSE CHANGED
@@ -176,7 +176,7 @@ recommend that a file or class name and description of purpose be included on
176
176
  the same "printed page" as the copyright notice for easier identification within
177
177
  third-party archives.
178
178
 
179
- Copyright 2025 Akamai Technologies, Inc. All rights reserved.
179
+ Copyright 2026 Akamai Technologies, Inc. All rights reserved.
180
180
 
181
181
  Licensed under the Apache License, Version 2.0 (the "License");
182
182
  you may not use these files except in compliance with the License.
package/README.md CHANGED
@@ -14,7 +14,7 @@ You can find the most up-to-date package in [NPM](https://www.npmjs.com/package/
14
14
 
15
15
  You can obtain the authentication credentials through an API client. Requests to the API are marked with a timestamp and a signature and are executed immediately.
16
16
 
17
- 1. [Create authentication credentials](https://techdocs.akamai.com/developer/docs/set-up-authentication-credentials).
17
+ 1. [Create authentication credentials](https://techdocs.akamai.com/developer/docs/edgegrid).
18
18
 
19
19
  2. Place your credentials in an EdgeGrid file `~/.edgerc`, in the `[default]` section.
20
20
 
@@ -168,6 +168,63 @@ eg.auth({
168
168
  });
169
169
  ```
170
170
 
171
+ ### Logging
172
+ The library supports configurable logging through the `enableLogging()` method.
173
+
174
+ - Enable logging with environment variables.
175
+ - `AKAMAI_LOG_LEVEL`. Sets the verbosity level of the emitted log messages. Valid values are `error`, `warn`, `info`, `debug`, `fatal`, and `trace`. Default to `info.`
176
+ - `AKAMAI_LOG_PRETTY`. Controls whether the log output is formatted in a human-friendly way. Valid values are `true` or `false`. Defaults to `false`.
177
+
178
+ ```javascript
179
+ const edgeGrid = require('akamai-edgegrid');
180
+
181
+ // Set environment variables before enabling logging
182
+ process.env.AKAMAI_LOG_LEVEL = 'debug';
183
+ process.env.AKAMAI_LOG_PRETTY = 'true';
184
+
185
+ var eg = new EdgeGrid({
186
+ path: '/path/to/.edgerc',
187
+ section: '<section-header>'
188
+ });
189
+ eg.enableLogging(true);
190
+ ```
191
+
192
+ - Disable logging.
193
+
194
+ ```javascript
195
+ const edgeGrid = require('akamai-edgegrid');
196
+ var eg = new EdgeGrid({
197
+ path: '/path/to/.edgerc',
198
+ section: '<section-header>'
199
+ });
200
+ eg.enableLogging(false);
201
+ ```
202
+
203
+ - Add a custom logger.
204
+ - You can also pass a custom logger object to the `enableLogging()` method. The object must have the `info`, `debug`, `error`, and `warn` methods.
205
+ - If you pass a logger object that doesn't implement the required methods, you'll get an error.
206
+
207
+ ```javascript
208
+ const edgeGrid = require('akamai-edgegrid');
209
+ // custom logger
210
+ const logger = {
211
+ info: (msg, ...args) => console.log('INFO:', msg, ...args),
212
+ debug: (msg, ...args) => console.log('DEBUG:', msg, ...args),
213
+ error: (msg, ...args) => console.error('ERROR:', msg, ...args),
214
+ warn: (msg, ...args) => console.warn('WARN:', msg, ...args)
215
+ };
216
+
217
+ var eg = new EdgeGrid({
218
+ path: '/path/to/.edgerc',
219
+ section: '<section-header>'
220
+ });
221
+
222
+ eg.enableLogging(logger); // Pass the custom logger
223
+
224
+ logger.info('Using custom logger for logging.');
225
+ logger.error('An error occurred!');
226
+ ```
227
+
171
228
  ### Proxy
172
229
 
173
230
  To use edgegrid with proxy, you can configure it with one of these methods:
@@ -203,36 +260,13 @@ To use edgegrid with proxy, you can configure it with one of these methods:
203
260
  $ node myapp.js
204
261
  ```
205
262
 
206
- ### Debug
207
-
208
- Enable debugging to get additional information about a request. You can configure this with one of these methods:
209
-
210
- - Add the `debug` argument to the `EdgeGrid()` method.
211
-
212
- ```javascript
213
- var eg = new EdgeGrid({
214
- path: '/path/to/.edgerc',
215
- section: 'section-header'
216
- debug: true
217
- });
218
- ```
219
-
220
- - Set the `EG_VERBOSE` environment variable.
221
-
222
- ```shell
223
- $ export EG_VERBOSE=true
224
- $ node src/main.js
225
- ```
226
-
227
-
228
-
229
263
  ## Reporting issues
230
264
 
231
265
  To report an issue or make a suggestion, create a new [GitHub issue](https://github.com/akamai/AkamaiOPEN-edgegrid-node/issues).
232
266
 
233
267
  ## License
234
268
 
235
- Copyright 2025 Akamai Technologies, Inc. All rights reserved.
269
+ Copyright 2026 Akamai Technologies, Inc. All rights reserved.
236
270
 
237
271
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
238
272
 
package/npm.log ADDED
@@ -0,0 +1,76 @@
1
+
2
+ added 395 packages, and audited 396 packages in 3s
3
+
4
+ 73 packages are looking for funding
5
+ run `npm fund` for details
6
+
7
+ 10 vulnerabilities (1 low, 9 high)
8
+
9
+ To address issues that do not require attention, run:
10
+ npm audit fix
11
+
12
+ To address all issues (including breaking changes), run:
13
+ npm audit fix --force
14
+
15
+ Run `npm audit` for details.
16
+ # npm audit report
17
+
18
+ axios 1.0.0 - 1.13.4
19
+ Severity: high
20
+ Axios is Vulnerable to Denial of Service via __proto__ Key in mergeConfig - https://github.com/advisories/GHSA-43fc-jf86-j433
21
+ fix available via `npm audit fix`
22
+ node_modules/axios
23
+
24
+ diff 6.0.0 - 8.0.2
25
+ jsdiff has a Denial of Service vulnerability in parsePatch and applyPatch - https://github.com/advisories/GHSA-73rr-hh4g-fpgx
26
+ fix available via `npm audit fix`
27
+ node_modules/diff
28
+ mocha >=1.10.0
29
+ Depends on vulnerable versions of diff
30
+ Depends on vulnerable versions of glob
31
+ Depends on vulnerable versions of minimatch
32
+ node_modules/mocha
33
+
34
+ minimatch <10.2.1
35
+ Severity: high
36
+ minimatch has a ReDoS via repeated wildcards with non-matching literal in pattern - https://github.com/advisories/GHSA-3ppc-4f35-3m26
37
+ fix available via `npm audit fix --force`
38
+ Will install nyc@10.1.2, which is a breaking change
39
+ node_modules/minimatch
40
+ node_modules/nyc/node_modules/minimatch
41
+ node_modules/rimraf/node_modules/minimatch
42
+ node_modules/test-exclude/node_modules/minimatch
43
+ glob 3.0.0 - 10.5.0
44
+ Depends on vulnerable versions of minimatch
45
+ node_modules/glob
46
+ node_modules/nyc/node_modules/glob
47
+ node_modules/rimraf/node_modules/glob
48
+ node_modules/test-exclude/node_modules/glob
49
+ nyc *
50
+ Depends on vulnerable versions of glob
51
+ Depends on vulnerable versions of istanbul-lib-processinfo
52
+ Depends on vulnerable versions of rimraf
53
+ Depends on vulnerable versions of spawn-wrap
54
+ Depends on vulnerable versions of test-exclude
55
+ node_modules/nyc
56
+ rimraf 2.3.0 - 3.0.2 || 4.2.0 - 5.0.10
57
+ Depends on vulnerable versions of glob
58
+ node_modules/rimraf
59
+ istanbul-lib-processinfo *
60
+ Depends on vulnerable versions of rimraf
61
+ node_modules/istanbul-lib-processinfo
62
+ spawn-wrap >=0.0.1
63
+ Depends on vulnerable versions of rimraf
64
+ node_modules/spawn-wrap
65
+ test-exclude 4.2.2 || >=5.0.0
66
+ Depends on vulnerable versions of glob
67
+ Depends on vulnerable versions of minimatch
68
+ node_modules/test-exclude
69
+
70
+ 10 vulnerabilities (1 low, 9 high)
71
+
72
+ To address issues that do not require attention, run:
73
+ npm audit fix
74
+
75
+ To address all issues (including breaking changes), run:
76
+ npm audit fix --force
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akamai-edgegrid",
3
- "version": "3.5.6",
3
+ "version": "4.0.1",
4
4
  "description": "Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,16 +17,20 @@
17
17
  "api",
18
18
  "edgegrid"
19
19
  ],
20
+ "exports": {
21
+ ".": "./index.js"
22
+ },
20
23
  "license": "Apache-2.0",
21
24
  "dependencies": {
22
25
  "axios": "^1.1.2",
23
- "log4js": "^6.4.0"
26
+ "pino": "^9.6.0"
24
27
  },
25
28
  "devDependencies": {
26
29
  "mocha": "^11.0.1",
27
30
  "mocha-junit-reporter": "^2.1.0",
28
31
  "nock": "^14.0.6",
29
- "nyc": "^17.0.0",
32
+ "nyc": "^18.0.0",
33
+ "pino-pretty": "^13.0.0",
30
34
  "tsd": "^0.33.0"
31
35
  }
32
36
  }
package/src/api.js CHANGED
@@ -2,7 +2,7 @@ const axios = require('axios'),
2
2
  auth = require('./auth'),
3
3
  edgerc = require('./edgerc'),
4
4
  helpers = require('./helpers'),
5
- logger = require('./logger');
5
+ { enableLogging, getLogger } = require('./logger');
6
6
 
7
7
  /**
8
8
  *
@@ -10,12 +10,11 @@ const axios = require('axios'),
10
10
  * @param {String} client_secret The client secret value from the .edgerc file.
11
11
  * @param {String} access_token The access token value from the .edgerc file.
12
12
  * @param {String} host The host a unique string followed by luna.akamaiapis.net from the .edgerc file.
13
- * @param {Boolean} debug The debug value allows to enable debugging.
14
13
  * @param {Number} max_body This value is deprecated.
15
14
  * @constructor
16
15
  * @deprecated max_body
17
16
  */
18
- const EdgeGrid = function (client_token, client_secret, access_token, host, debug, max_body) {
17
+ const EdgeGrid = function (client_token, client_secret, access_token, host, max_body) {
19
18
  // accepting an object containing a path to .edgerc and a config section
20
19
  if (typeof arguments[0] === 'object') {
21
20
  let edgercPath = arguments[0];
@@ -23,16 +22,16 @@ const EdgeGrid = function (client_token, client_secret, access_token, host, debu
23
22
  } else {
24
23
  this._setConfigFromStrings(client_token, client_secret, access_token, host);
25
24
  }
26
- if (process.env.EG_VERBOSE || debug || (typeof arguments[0] === 'object' && arguments[0].debug)) {
27
- axios.interceptors.request.use(request => {
28
- console.log('Starting Request', request);
29
- return request;
30
- });
31
- axios.interceptors.response.use(response => {
32
- console.log('Response:', response);
33
- return response;
34
- });
35
- }
25
+
26
+ axios.interceptors.request.use(request => {
27
+ getLogger().debug({ request }, 'Starting request');
28
+ return request;
29
+ });
30
+
31
+ axios.interceptors.response.use(response => {
32
+ getLogger().debug({ response }, 'Received response');
33
+ return response;
34
+ });
36
35
  };
37
36
 
38
37
  /**
@@ -143,7 +142,7 @@ function validatedArgs(args) {
143
142
 
144
143
  expected.forEach(function (arg, i) {
145
144
  if (!args[i]) {
146
- logger.error('No defined ' + arg);
145
+ getLogger().error({ arg }, 'No defined argument');
147
146
  valid = false;
148
147
  }
149
148
  });
@@ -161,4 +160,17 @@ EdgeGrid.prototype._setConfigFromObj = function (obj) {
161
160
  this.config = edgerc(obj.path, obj.section);
162
161
  };
163
162
 
163
+ /**
164
+ * Enables logging based on the provided option.
165
+ *
166
+ * @param {boolean|object} option - If true, configures the logger using environment variables.
167
+ * If a valid object, uses it as the logger instance.
168
+ * If false, disables logging.
169
+ * @return EdgeGrid object (self)
170
+ */
171
+ EdgeGrid.prototype.enableLogging = function(option) {
172
+ enableLogging(option);
173
+ return this;
174
+ };
175
+
164
176
  module.exports = EdgeGrid;
package/src/auth.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const { randomUUID } = require('crypto'),
2
2
  helpers = require('./helpers'),
3
- logger = require('./logger'),
3
+ { getLogger } = require('./logger'),
4
4
  url = require('url');
5
5
 
6
6
  /**
@@ -36,11 +36,11 @@ function makeAuthHeader(request, clientToken, accessToken, clientSecret, timesta
36
36
 
37
37
  authHeader = 'EG1-HMAC-SHA256 ' + joinedPairs;
38
38
 
39
- logger.info('Unsigned authorization header: ' + authHeader + '\n');
39
+ getLogger().info({ authHeader }, 'Unsigned authorization header');
40
40
 
41
41
  signedAuthHeader = authHeader + 'signature=' + helpers.signRequest(request, timestamp, clientSecret, authHeader, maxBody);
42
42
 
43
- logger.info('Signed authorization header: ' + signedAuthHeader + '\n');
43
+ getLogger().info({ signedAuthHeader }, 'Signed authorization header');
44
44
 
45
45
  return signedAuthHeader;
46
46
  }
package/src/edgerc.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const fs = require('fs'),
2
- logger = require('./logger'),
2
+ { getLogger } = require('./logger'),
3
3
  helpers = require('./helpers');
4
4
 
5
5
  function getSection(lines, sectionName) {
@@ -41,7 +41,7 @@ function validatedConfig(config) {
41
41
  errorMessage += "\nMissing: " + token;
42
42
  }
43
43
  });
44
- console.log('Missing part of the configuration:\n' + errorMessage);
44
+ getLogger().error({ errorMessage }, 'Missing part of the configuration');
45
45
  return {};
46
46
  }
47
47
 
@@ -91,6 +91,7 @@ function buildObj(configs) {
91
91
  }
92
92
 
93
93
  function readEnv(section) {
94
+ var logger = getLogger();
94
95
  const requiredKeys = ["HOST", "ACCESS_TOKEN", "CLIENT_TOKEN", "CLIENT_SECRET"],
95
96
  prefix = !section || section === "default" ? "AKAMAI_" : "AKAMAI_" + section.toUpperCase() + "_",
96
97
  envConfig = {};
@@ -99,7 +100,7 @@ function readEnv(section) {
99
100
  for (const key of requiredKeys) {
100
101
  const varName = prefix + key;
101
102
  if (!process.env[varName]) {
102
- logger.debug("Environment variable not set: " + varName);
103
+ logger.debug({ varName }, 'Environment variable not set');
103
104
  continue;
104
105
  }
105
106
  envConfig[key.toLowerCase()] = process.env[prefix + key];
@@ -107,7 +108,7 @@ function readEnv(section) {
107
108
  if (Object.keys(envConfig).length < requiredKeys.length) {
108
109
  return {};
109
110
  }
110
- console.log("Using configuration from environment variables");
111
+ logger.info('Using configuration from environment variables');
111
112
  return validatedConfig(envConfig);
112
113
  }
113
114
 
package/src/helpers.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const crypto = require('crypto'),
2
- logger = require('./logger'),
2
+ { getLogger } = require('./logger'),
3
3
  path = require('path'),
4
4
  os = require('os');
5
5
  const MAX_BODY = 131072
@@ -29,7 +29,7 @@ module.exports = {
29
29
  '+0000';
30
30
  },
31
31
  contentHash: function (request) {
32
-
32
+ var logger = getLogger()
33
33
  let contentHash = '',
34
34
  preparedBody = request.body || '',
35
35
  isTarball = preparedBody instanceof Uint8Array && request.headers['Content-Type'] === 'application/gzip';
@@ -51,27 +51,31 @@ module.exports = {
51
51
  request.body = preparedBody; // Is this required or being used?
52
52
  }
53
53
 
54
- logger.info('Body is \"' + preparedBody + '\"');
55
- logger.debug('PREPARED BODY LENGTH', preparedBody.length);
54
+ logger.info({ body: preparedBody }, 'Body');
55
+ logger.debug({ length: preparedBody.length }, 'Prepared body length');
56
56
 
57
57
  if (request.method === 'POST' && preparedBody.length > 0) {
58
58
 
59
- logger.info('Signing content: \"' + preparedBody + '\"');
59
+ logger.info({ body: preparedBody }, 'Signing content');
60
60
 
61
61
  // If body data is too large, cut down to max-body size which is const value
62
62
  if (preparedBody.length > MAX_BODY) {
63
- logger.warn('Data length (' + preparedBody.length + ') is larger than maximum ' + MAX_BODY);
63
+ logger.warn({
64
+ length: preparedBody.length,
65
+ maxAllowed: MAX_BODY,
66
+ }, 'Data length exceeds maximum allowed');
67
+
64
68
  if (isTarball)
65
69
  preparedBody = preparedBody.slice(0, MAX_BODY);
66
70
  else
67
71
  preparedBody = preparedBody.substring(0, MAX_BODY);
68
- logger.info('Body truncated. New value \"' + preparedBody + '\"');
72
+ logger.info({ newBody: preparedBody }, 'Body truncated');
69
73
  }
70
74
 
71
- logger.debug('PREPARED BODY', preparedBody);
75
+ logger.debug({ preparedBody }, 'Prepared body content');
72
76
 
73
77
  contentHash = this.base64Sha256(preparedBody);
74
- logger.info('Content hash is \"' + contentHash + '\"');
78
+ logger.info({ hash: contentHash }, 'Content hash is');
75
79
  }
76
80
 
77
81
  return contentHash;
@@ -100,7 +104,7 @@ module.exports = {
100
104
 
101
105
  const dataToSignStr = dataToSign.join('\t').toString();
102
106
 
103
- logger.info('Data to sign: "' + dataToSignStr + '" \n');
107
+ getLogger().info({ data: dataToSignStr }, 'Data to sign');
104
108
 
105
109
  return dataToSignStr;
106
110
  },
@@ -180,7 +184,7 @@ module.exports = {
180
184
  signingKey: function (timestamp, clientSecret) {
181
185
  const key = this.base64HmacSha256(timestamp, clientSecret);
182
186
 
183
- logger.info('Signing key: ' + key + '\n');
187
+ getLogger().info({ key }, 'Signing key used');
184
188
 
185
189
  return key;
186
190
  },
package/src/logger.js CHANGED
@@ -1,12 +1,82 @@
1
- const log4js = require('log4js'),
2
- logger = log4js.getLogger();
1
+ const pino = require('pino');
3
2
 
4
- if (!process.env.LOG4JS_CONFIG) {
5
- logger.level = log4js.levels.ERROR;
3
+ const VALID_LEVELS = ['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent'];
4
+
5
+ const silentLogger = createLogger({level: 'silent'});
6
+
7
+ // zero logging by default.
8
+ let currentLogger = silentLogger;
9
+
10
+ /**
11
+ * Enables logging based on the provided option.
12
+ *
13
+ * @param {boolean|object} option - If true, configures the logger using environment variables.
14
+ * If an valid object, uses it as the logger instance.
15
+ * Otherwise, reverts to silent logging.
16
+ */
17
+ function enableLogging(option) {
18
+ if (option === true) {
19
+ const envLogLevel = process.env.AKAMAI_LOG_LEVEL || 'info';
20
+ if (!VALID_LEVELS.includes(envLogLevel)) {
21
+ throw new Error(`Invalid AKAMAI_LOG_LEVEL value "${envLogLevel}". Expected one of: ${VALID_LEVELS.join(', ')}.`);
22
+ }
23
+ currentLogger = createLogger({
24
+ level: envLogLevel,
25
+ pretty: process.env.AKAMAI_LOG_PRETTY === 'true'
26
+ });
27
+ } else if (option === false) {
28
+ currentLogger = silentLogger;
29
+ } else if (isValidLoggerObject(option)) {
30
+ currentLogger = option;
31
+ } else {
32
+ throw new Error('Invalid argument passed to enableLogging. Expected true, false, or a logger object.');
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Checks if the provided object implements the necessary logger methods.
38
+ *
39
+ * @param {Object} option - The object to validate.
40
+ * @returns {boolean} - Returns true if the object is a valid logger, false otherwise.
41
+ */
42
+ function isValidLoggerObject(option) {
43
+ return ['info', 'debug', 'error', 'warn'].every(fn => typeof option[fn] === 'function');
44
+ }
45
+
46
+ /**
47
+ * Creates and configures a Pino logger instance.
48
+ *
49
+ * @param {Object} options - Configuration options for the logger.
50
+ * @param {string} [options.level='info'] - The minimum level of logs to output.
51
+ * @param {boolean} [options.pretty=false] - Whether to enable pretty-printing of logs.
52
+ * @returns {Object} - Configured Pino logger instance.
53
+ */
54
+ function createLogger({level = 'info', pretty = false} = {}) {
55
+ return pino({
56
+ level,
57
+ timestamp: () => `,"time":"${new Date().toISOString()}"`,
58
+ transport: pretty ? {
59
+ target: 'pino-pretty',
60
+ options: {
61
+ colorize: true,
62
+ translateTime: 'yyyy-mm-dd HH:MM:ss.l',
63
+ ignore: 'pid,hostname'
64
+ }
65
+ } : undefined
66
+ });
67
+ }
68
+
69
+ /**
70
+ * Returns the current logger instance.
71
+ */
72
+ function getLogger() {
73
+ return currentLogger;
6
74
  }
7
75
 
8
- if (process.env.EDGEGRID_ENV === 'test') {
9
- logger.level = log4js.levels.OFF;
76
+ if (process.env.EDGEGRID_ENV !== 'test') {
77
+ if (process.env.AKAMAI_LOG_LEVEL || process.env.AKAMAI_LOG_PRETTY) {
78
+ enableLogging(true);
79
+ }
10
80
  }
11
81
 
12
- module.exports = logger;
82
+ module.exports = { enableLogging, getLogger };
@@ -0,0 +1,40 @@
1
+ const assert = require('assert');
2
+ const logger = require('../../src/logger');
3
+
4
+ describe('enableLogging', function () {
5
+ it('should accept a custom logger object', function () {
6
+ const logs = [];
7
+ const customLogger = {
8
+ info: (msg) => logs.push(`INFO: ${msg}`),
9
+ debug: (msg) => logs.push(`DEBUG: ${msg}`),
10
+ error: (msg) => logs.push(`ERROR: ${msg}`),
11
+ warn: (msg) => logs.push(`WARN: ${msg}`)
12
+ };
13
+
14
+ logger.enableLogging(customLogger);
15
+
16
+ const log = logger.getLogger();
17
+ log.info('test info');
18
+ log.debug('test debug');
19
+ log.error('test error');
20
+ log.warn('test warn');
21
+
22
+ assert.strictEqual(logs[0], 'INFO: test info');
23
+ assert.strictEqual(logs[1], 'DEBUG: test debug');
24
+ assert.strictEqual(logs[2], 'ERROR: test error');
25
+ assert.strictEqual(logs[3], 'WARN: test warn');
26
+ });
27
+
28
+ it('should throw an error for an invalid custom logger object', function () {
29
+ const invalidLogger = {
30
+ info: () => {} // Missing 'debug', 'error', 'warn' methods
31
+ };
32
+
33
+ try {
34
+ logger.enableLogging(invalidLogger);
35
+ assert.fail('Expected error to be thrown'); // If no error is thrown, this will fail
36
+ } catch (error) {
37
+ assert.strictEqual(error.message, 'Invalid argument passed to enableLogging. Expected true, false, or a logger object.');
38
+ }
39
+ });
40
+ });