@akinon/next 1.93.0-rc.46 → 1.93.0-rc.48

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,17 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.93.0-rc.48
4
+
5
+ ### Minor Changes
6
+
7
+ - 185396f: ZERO-3569: Refactor logging in cache handler to use console_log instead of logger
8
+
9
+ ## 1.93.0-rc.47
10
+
11
+ ### Minor Changes
12
+
13
+ - 3e4aadc: ZERO-3569: Fix import statement for logger in cache handler
14
+
3
15
  ## 1.93.0-rc.46
4
16
 
5
17
  ### Minor Changes
@@ -2,7 +2,6 @@ import { CacheHandler } from '@neshca/cache-handler';
2
2
  import createLruHandler from '@neshca/cache-handler/local-lru';
3
3
  import createRedisHandler from '@neshca/cache-handler/redis-strings';
4
4
  import { createClient } from 'redis';
5
- import logger from '../utils/log.js';
6
5
 
7
6
  // Cache configuration
8
7
  const CACHE_CONFIG = {
@@ -32,10 +31,22 @@ if (!globalForRedis.redisClient) {
32
31
  globalForRedis.connectionAttempts = 0;
33
32
  }
34
33
 
34
+ // Logging configuration
35
+ const debugValue = process.env.NEXT_PRIVATE_DEBUG_CACHE;
36
+ const debug = debugValue === 'true' || debugValue === '1';
37
+
38
+ let console_log;
39
+ if (debug) {
40
+ // eslint-disable-next-line no-console
41
+ console_log = (...args) => console.log('[Cache Handler]', ...args);
42
+ } else {
43
+ console_log = () => {};
44
+ }
45
+
35
46
  async function getRedisClient() {
36
47
  // If client exists and is ready, return it
37
48
  if (globalForRedis.redisClient?.isReady) {
38
- logger.trace('Reusing existing Redis connection');
49
+ console_log('Reusing existing Redis connection');
39
50
  return globalForRedis.redisClient;
40
51
  }
41
52
 
@@ -53,7 +64,7 @@ async function getRedisClient() {
53
64
  const redisUrl = `redis://${CACHE_CONFIG.host}:${CACHE_CONFIG.port}/${CACHE_CONFIG.bucket}`;
54
65
 
55
66
  if (globalForRedis.connectionAttempts === 1) {
56
- logger.debug('Creating Redis connection', { url: redisUrl });
67
+ console_log('Creating Redis connection:', redisUrl);
57
68
  }
58
69
 
59
70
  const redisClient = createClient({
@@ -62,8 +73,8 @@ async function getRedisClient() {
62
73
  reconnectStrategy: (retries) => {
63
74
  if (retries > CACHE_CONFIG.redis.reconnectStrategy.maxRetries) {
64
75
  if (!globalForRedis.hasLoggedConnectionError) {
65
- logger.debug(
66
- 'Redis is not available, falling back to local cache only'
76
+ console.warn(
77
+ '[Cache Handler] Redis is not available, falling back to local cache only'
67
78
  );
68
79
  globalForRedis.hasLoggedConnectionError = true;
69
80
  }
@@ -79,23 +90,23 @@ async function getRedisClient() {
79
90
  // Only log the first connection error to avoid spam
80
91
  if (!globalForRedis.hasLoggedConnectionError) {
81
92
  if (error.code === 'ECONNREFUSED') {
82
- logger.debug(
83
- 'Redis connection refused. Is Redis running? Falling back to local cache.'
93
+ console.warn(
94
+ '[Cache Handler] Redis connection refused. Is Redis running? Falling back to local cache.'
84
95
  );
85
96
  } else {
86
- logger.warn('Redis client error', { error: error.message });
97
+ console.error('[Cache Handler] Redis client error:', error.message);
87
98
  }
88
99
  globalForRedis.hasLoggedConnectionError = true;
89
100
  }
90
101
  });
91
102
 
92
103
  redisClient.on('connect', () => {
93
- logger.debug('Redis connected');
104
+ console_log('Redis connected');
94
105
  globalForRedis.hasLoggedConnectionError = false;
95
106
  });
96
107
 
97
108
  redisClient.on('ready', () => {
98
- logger.debug('Redis ready');
109
+ console_log('Redis ready');
99
110
  globalForRedis.hasLoggedConnectionError = false;
100
111
  });
101
112
 
@@ -105,9 +116,14 @@ async function getRedisClient() {
105
116
  } catch (error) {
106
117
  if (!globalForRedis.hasLoggedConnectionError) {
107
118
  if (error.code === 'ECONNREFUSED') {
108
- logger.debug('Could not connect to Redis - using local cache only');
119
+ console.warn(
120
+ '[Cache Handler] Could not connect to Redis - using local cache only'
121
+ );
109
122
  } else {
110
- logger.error('Failed to connect to Redis', { error: error.message });
123
+ console.error(
124
+ '[Cache Handler] Failed to connect to Redis:',
125
+ error.message
126
+ );
111
127
  }
112
128
  globalForRedis.hasLoggedConnectionError = true;
113
129
  }
@@ -119,7 +135,7 @@ async function getRedisClient() {
119
135
  }
120
136
 
121
137
  CacheHandler.onCreation(async () => {
122
- logger.debug('Initializing cache handlers...');
138
+ console_log('Initializing cache handlers...');
123
139
 
124
140
  let client;
125
141
  try {
@@ -163,68 +179,69 @@ CacheHandler.onCreation(async () => {
163
179
  name: 'custom-local-then-redis',
164
180
  get: async (key, context) => {
165
181
  const vKey = versionKey(key);
166
- logger.trace('GET called for key', {
167
- key: typeof vKey === 'string' ? vKey : vKey?.key
168
- });
182
+ console_log(
183
+ 'GET called for key:',
184
+ typeof vKey === 'string' ? vKey : vKey?.key
185
+ );
169
186
 
170
187
  // Check local cache first
171
- logger.trace('Checking local cache...');
188
+ console_log('Checking local cache...');
172
189
  const localResult = await localHandler.get(vKey, context);
173
190
 
174
191
  if (localResult) {
175
- logger.trace('Found in local cache');
192
+ console_log('Found in local cache');
176
193
  return localResult;
177
194
  }
178
195
 
179
- logger.trace('Not found in local, checking Redis...');
196
+ console_log('Not found in local, checking Redis...');
180
197
  try {
181
198
  const redisResult = await redisHandler.get(vKey, context);
182
199
 
183
200
  if (redisResult) {
184
- logger.trace('Found in Redis');
201
+ console_log('Found in Redis');
185
202
  // Sync back to local cache for faster future access
186
203
  try {
187
204
  await localHandler.set(vKey, redisResult, context);
188
- logger.trace('Synced to local cache');
205
+ console_log('Synced to local cache');
189
206
  } catch (error) {
190
- logger.debug('Failed to sync to local', { error: error.message });
207
+ console_log('Failed to sync to local:', error.message);
191
208
  }
192
209
  return redisResult;
193
210
  }
194
211
  } catch (error) {
195
- logger.warn('Redis GET operation failed', { error: error.message });
212
+ console_log('Redis error:', error.message);
196
213
  }
197
214
 
198
- logger.trace('Not found in any cache');
215
+ console_log('Not found in any cache');
199
216
  return undefined;
200
217
  },
201
218
  set: async (key, value, context) => {
202
219
  const vKey = versionKey(key);
203
- logger.trace('SET called for key', {
204
- key: typeof vKey === 'string' ? vKey : vKey?.key
205
- });
220
+ console_log(
221
+ 'SET called for key:',
222
+ typeof vKey === 'string' ? vKey : vKey?.key
223
+ );
206
224
  // Set to both caches
207
225
  await Promise.allSettled([
208
226
  localHandler.set(vKey, value, context),
209
227
  redisHandler
210
228
  .set(vKey, value, context)
211
- .catch((error) =>
212
- logger.warn('Redis SET operation failed', { error: error.message })
213
- )
229
+ .catch((error) => console_log('Redis SET error:', error.message))
214
230
  ]);
215
231
  },
216
232
  delete: async (key, context) => {
217
233
  const vKey = versionKey(key);
218
- logger.trace('DELETE called for key', {
219
- key: typeof vKey === 'string' ? vKey : vKey?.key
220
- });
234
+ console_log(
235
+ 'DELETE called for key:',
236
+ typeof vKey === 'string' ? vKey : vKey?.key
237
+ );
221
238
  await Promise.allSettled([
222
239
  localHandler.delete?.(vKey, context),
223
240
  redisHandler.delete?.(vKey, context)
224
241
  ]);
225
242
  },
226
243
  revalidateTag: async (tags, context) => {
227
- logger.debug('REVALIDATE_TAG called for tags', { tags });
244
+ console_log('REVALIDATE_TAG called for tags:', tags);
228
245
  await Promise.allSettled([
229
246
  localHandler.revalidateTag?.(tags, context),
230
247
  redisHandler.revalidateTag?.(tags, context)
@@ -232,7 +249,7 @@ CacheHandler.onCreation(async () => {
232
249
  }
233
250
  };
234
251
 
235
- logger.info('Cache handlers initialized successfully');
252
+ console_log('[Cache Handler] Handlers initialized successfully');
236
253
 
237
254
  return {
238
255
  handlers: [customHandler]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.93.0-rc.46",
4
+ "version": "1.93.0-rc.48",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -34,7 +34,7 @@
34
34
  "set-cookie-parser": "2.6.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@akinon/eslint-plugin-projectzero": "1.93.0-rc.46",
37
+ "@akinon/eslint-plugin-projectzero": "1.93.0-rc.48",
38
38
  "@babel/core": "7.26.10",
39
39
  "@babel/preset-env": "7.26.9",
40
40
  "@babel/preset-typescript": "7.27.0",