honeyweb-core 2.0.3 → 2.0.4

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/utils/logger.js CHANGED
@@ -1,12 +1,6 @@
1
1
  // honeyweb-core/utils/logger.js
2
- // Structured logging utility
3
2
 
4
- const LOG_LEVELS = {
5
- debug: 0,
6
- info: 1,
7
- warn: 2,
8
- error: 3
9
- };
3
+ const LOG_LEVELS = { debug: 0, info: 1, warn: 2, error: 3 };
10
4
 
11
5
  class Logger {
12
6
  constructor(config = {}) {
@@ -23,48 +17,31 @@ class Logger {
23
17
  const timestamp = new Date().toISOString();
24
18
 
25
19
  if (this.format === 'json') {
26
- return JSON.stringify({
27
- timestamp,
28
- level: level.toUpperCase(),
29
- message,
30
- ...meta
31
- });
20
+ return JSON.stringify({ timestamp, level: level.toUpperCase(), message, ...meta });
32
21
  }
33
22
 
34
- // Pretty format
35
- const metaStr = Object.keys(meta).length > 0
36
- ? ' ' + JSON.stringify(meta)
37
- : '';
23
+ const metaStr = Object.keys(meta).length > 0 ? ' ' + JSON.stringify(meta) : '';
38
24
  return `${this.prefix} [${level.toUpperCase()}] ${message}${metaStr}`;
39
25
  }
40
26
 
41
27
  debug(message, meta) {
42
- if (this._shouldLog('debug')) {
43
- console.log(this._formatMessage('debug', message, meta));
44
- }
28
+ if (this._shouldLog('debug')) console.log(this._formatMessage('debug', message, meta));
45
29
  }
46
30
 
47
31
  info(message, meta) {
48
- if (this._shouldLog('info')) {
49
- console.log(this._formatMessage('info', message, meta));
50
- }
32
+ if (this._shouldLog('info')) console.log(this._formatMessage('info', message, meta));
51
33
  }
52
34
 
53
35
  warn(message, meta) {
54
- if (this._shouldLog('warn')) {
55
- console.warn(this._formatMessage('warn', message, meta));
56
- }
36
+ if (this._shouldLog('warn')) console.warn(this._formatMessage('warn', message, meta));
57
37
  }
58
38
 
59
39
  error(message, meta) {
60
- if (this._shouldLog('error')) {
61
- console.error(this._formatMessage('error', message, meta));
62
- }
40
+ if (this._shouldLog('error')) console.error(this._formatMessage('error', message, meta));
63
41
  }
64
42
 
65
- // Convenience methods for common HoneyWeb events
66
43
  trapTriggered(ip, path) {
67
- this.warn(`🚨 TRAP TRIGGERED by ${ip} on ${path}`, { ip, path, event: 'trap_triggered' });
44
+ this.warn(`TRAP TRIGGERED by ${ip} on ${path}`, { ip, path, event: 'trap_triggered' });
68
45
  }
69
46
 
70
47
  ipBanned(ip, reason) {
@@ -73,10 +50,7 @@ class Logger {
73
50
 
74
51
  threatDetected(ip, threats, level) {
75
52
  this.warn(`THREAT DETECTED from ${ip}: ${threats.join(', ')} (level: ${level})`, {
76
- ip,
77
- threats,
78
- threatLevel: level,
79
- event: 'threat_detected'
53
+ ip, threats, threatLevel: level, event: 'threat_detected'
80
54
  });
81
55
  }
82
56