azify-logger 1.0.25 → 1.0.28

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/README.md CHANGED
@@ -146,7 +146,14 @@ cp env/app.env.example env/app.env
146
146
  cp env/grafana.env.example env/grafana.env
147
147
  ```
148
148
 
149
- Edite `env/app.env` e `env/grafana.env` com suas configurações do Azure AD e outras variáveis.
149
+ #### Importante: configure seu e-mail para ser promovido a Admin
150
+ 1. Abra `env/grafana.env`.
151
+ 2. Atualize `ADMIN_GLOBAL_EMAIL` com **seu e-mail corporativo** (ex.: `ADMIN_GLOBAL_EMAIL=seu.email@exemplo.com`).
152
+ 3. Abra `env/app.env`.
153
+ 4. Garanta que `ADMIN_EMAILS` contenha o mesmo e-mail (ex.: `ADMIN_EMAILS=seu.email@exemplo.com`).
154
+ 5. Salve os arquivos e reinicie os containers (`./start-docker.sh`).
155
+
156
+ Assim, ao fazer login com Azure AD, você é promovido automaticamente a Server Admin e já enxerga o Explore e os dashboards da sua aplicação.
150
157
 
151
158
  ### Testar
152
159
 
package/index.js CHANGED
@@ -1,4 +1,11 @@
1
- const axios = require('axios')
1
+ const { createHttpLoggerTransport } = require('./streams/httpQueue')
2
+ const nativeConsole = {
3
+ log: console.log.bind(console),
4
+ error: console.error.bind(console),
5
+ warn: console.warn.bind(console),
6
+ info: console.info.bind(console),
7
+ debug: console.debug.bind(console)
8
+ }
2
9
 
3
10
  let context, propagation, trace, W3CTraceContextPropagator
4
11
  try {
@@ -34,13 +41,23 @@ class AzifyLogger {
34
41
  * @param {string} [options.environment] - Environment name (defaults to NODE_ENV or 'development')
35
42
  */
36
43
  constructor(options = {}) {
44
+ const fallbackLoggerUrl = process.env.AZIFY_LOGGER_URL || 'http://localhost:3001/log'
45
+ const fallbackEnvironment = process.env.NODE_ENV || 'development'
46
+
37
47
  this.options = {
38
- serviceName: options.serviceName || 'azipay',
39
- loggerUrl: options.loggerUrl || 'http://localhost:3001',
40
- environment: options.environment || process.env.NODE_ENV || 'development',
48
+ serviceName: options.serviceName || process.env.APP_NAME || 'application',
49
+ loggerUrl: options.loggerUrl || fallbackLoggerUrl,
50
+ environment: options.environment || fallbackEnvironment,
51
+ awaitDelivery: options.awaitDelivery !== undefined
52
+ ? Boolean(options.awaitDelivery)
53
+ : process.env.AZIFY_LOGGER_AWAIT_DELIVERY === 'true',
41
54
  ...options
42
55
  }
43
56
 
57
+ this.transport = createHttpLoggerTransport(this.options.loggerUrl, {
58
+ awaitDelivery: this.options.awaitDelivery
59
+ })
60
+
44
61
  this.propagator = new W3CTraceContextPropagator()
45
62
  propagation.setGlobalPropagator(this.propagator)
46
63
  }
@@ -84,15 +101,17 @@ class AzifyLogger {
84
101
  carrier[key] = value
85
102
  }
86
103
  })
87
- } catch (_) {}
104
+ } catch (_) { }
88
105
 
89
- await axios.post(`${this.options.loggerUrl}`, logData, {
90
- timeout: 5000,
91
- headers
92
- })
93
- } catch (error) {
94
- console.error('Erro ao enviar log:', error.message)
95
- }
106
+ if (this.transport && typeof this.transport.enqueue === 'function') {
107
+ try {
108
+ this.transport.enqueue(logData, headers)
109
+ if (this.options.awaitDelivery && typeof this.transport.flush === 'function') {
110
+ this.transport.flush().catch(() => { })
111
+ }
112
+ } catch (err) { }
113
+ }
114
+ } catch (error) { }
96
115
  }
97
116
 
98
117
  /**
@@ -170,9 +189,9 @@ function createAzifyLogger(options = {}) {
170
189
  */
171
190
  function createAzifyLoggerFromEnv() {
172
191
  const logger = createAzifyLogger({
173
- serviceName: process.env.APP_NAME || 'azipay',
174
- loggerUrl: process.env.AZIFY_LOGGER_URL || 'http://localhost:3001',
175
- environment: process.env.NODE_ENV || 'development'
192
+ serviceName: process.env.APP_NAME,
193
+ loggerUrl: process.env.AZIFY_LOGGER_URL,
194
+ environment: process.env.NODE_ENV
176
195
  })
177
196
 
178
197
  interceptConsole(logger)
@@ -323,4 +342,7 @@ module.exports.streams = {
323
342
  module.exports.middleware = {
324
343
  restify: require('./middleware-restify'),
325
344
  express: require('./middleware-express')
326
- }
345
+ }
346
+ module.exports.startLoggerWorker = require('./queue/workerManager').startLoggerWorker
347
+ module.exports.stopLoggerWorker = require('./queue/workerManager').stopLoggerWorker
348
+ module.exports.ensureLoggerWorker = require('./queue/workerManager').ensureWorker