Преглед на файлове

[misc] silence logger when running tests (#22243)

* [misc] silence logger when running tests

* [misc] re-enable logging in some tests for scripts

* [misc] make it easy to turn on verbose logging for tests

```
LOG_LEVEL=debug make test_unit
LOG_LEVEL=debug make test_acceptance
```
GitOrigin-RevId: 219bc6d1f9cbdb89ddd7d94742920913ddde4514
Jakob Ackermann преди 1 година
родител
ревизия
0a7b2004d2

+ 3 - 1
libraries/logger/logging-manager.js

@@ -14,8 +14,10 @@ const LoggingManager = {
   initialize(name) {
     this.isProduction =
       (process.env.NODE_ENV || '').toLowerCase() === 'production'
+    const isTest = (process.env.NODE_ENV || '').toLowerCase() === 'test'
     this.defaultLevel =
-      process.env.LOG_LEVEL || (this.isProduction ? 'info' : 'debug')
+      process.env.LOG_LEVEL ||
+      (this.isProduction ? 'info' : isTest ? 'fatal' : 'debug')
     this.loggerName = name
     this.logger = bunyan.createLogger({
       name,

+ 2 - 1
services/chat/docker-compose.yml

@@ -14,6 +14,7 @@ services:
     working_dir: /overleaf/services/chat
     environment:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit
@@ -31,7 +32,7 @@ services:
       MONGO_HOST: mongo
       POSTGRES_HOST: postgres
       MOCHA_GREP: ${MOCHA_GREP}
-      LOG_LEVEL: ERROR
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     user: node

+ 2 - 1
services/clsi/docker-compose.yml

@@ -17,6 +17,7 @@ services:
     working_dir: /overleaf/services/clsi
     environment:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit
@@ -37,7 +38,7 @@ services:
       MONGO_HOST: mongo
       POSTGRES_HOST: postgres
       MOCHA_GREP: ${MOCHA_GREP}
-      LOG_LEVEL: ERROR
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
       ENABLE_PDF_CACHING: "true"

+ 0 - 3
services/clsi/test/acceptance/js/helpers/ClsiApp.js

@@ -10,8 +10,6 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 const app = require('../../../../app')
-require('@overleaf/logger').logger.level('info')
-const logger = require('@overleaf/logger')
 const Settings = require('@overleaf/settings')
 
 module.exports = {
@@ -37,7 +35,6 @@ module.exports = {
             throw error
           }
           this.running = true
-          logger.info('clsi running in dev mode')
 
           return (() => {
             const result = []

+ 2 - 1
services/contacts/docker-compose.yml

@@ -14,6 +14,7 @@ services:
     working_dir: /overleaf/services/contacts
     environment:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit
@@ -31,7 +32,7 @@ services:
       MONGO_HOST: mongo
       POSTGRES_HOST: postgres
       MOCHA_GREP: ${MOCHA_GREP}
-      LOG_LEVEL: ERROR
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     user: node

+ 2 - 1
services/docstore/docker-compose.yml

@@ -14,6 +14,7 @@ services:
     working_dir: /overleaf/services/docstore
     environment:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit
@@ -34,7 +35,7 @@ services:
       GCS_PROJECT_ID: fake
       STORAGE_EMULATOR_HOST: http://gcs:9090/storage/v1
       MOCHA_GREP: ${MOCHA_GREP}
-      LOG_LEVEL: ERROR
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     user: node

+ 0 - 1
services/docstore/test/acceptance/js/helpers/DocstoreApp.js

@@ -1,5 +1,4 @@
 const app = require('../../../../app')
-require('@overleaf/logger').logger.level('error')
 const settings = require('@overleaf/settings')
 
 module.exports = {

+ 2 - 1
services/document-updater/docker-compose.yml

@@ -14,6 +14,7 @@ services:
     working_dir: /overleaf/services/document-updater
     environment:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit
@@ -34,7 +35,7 @@ services:
       MONGO_HOST: mongo
       POSTGRES_HOST: postgres
       MOCHA_GREP: ${MOCHA_GREP}
-      LOG_LEVEL: ERROR
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     user: node

+ 0 - 1
services/document-updater/test/acceptance/js/helpers/DocUpdaterApp.js

@@ -9,7 +9,6 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 const app = require('../../../../app')
-require('@overleaf/logger').logger.level('fatal')
 
 module.exports = {
   running: false,

+ 2 - 1
services/filestore/docker-compose.yml

@@ -17,6 +17,7 @@ services:
     working_dir: /overleaf/services/filestore
     environment:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit
@@ -47,7 +48,7 @@ services:
       GCS_PROJECT_ID: fake
       STORAGE_EMULATOR_HOST: http://gcs:9090/storage/v1
       MOCHA_GREP: ${MOCHA_GREP}
-      LOG_LEVEL: ERROR
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
       ENABLE_CONVERSIONS: "true"

+ 0 - 3
services/filestore/test/acceptance/js/FilestoreApp.js

@@ -1,12 +1,9 @@
-const logger = require('@overleaf/logger')
 const ObjectPersistor = require('@overleaf/object-persistor')
 const Settings = require('@overleaf/settings')
 const { promisify } = require('node:util')
 const App = require('../../../app')
 const FileHandler = require('../../../app/js/FileHandler')
 
-logger.logger.level('info')
-
 class FilestoreApp {
   async runServer() {
     if (!this.server) {

+ 2 - 1
services/history-v1/docker-compose.yml

@@ -17,6 +17,7 @@ services:
     working_dir: /overleaf/services/history-v1
     environment:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit
@@ -47,7 +48,7 @@ services:
       GCS_PROJECT_ID: fake
       STORAGE_EMULATOR_HOST: http://gcs:9090/storage/v1
       MOCHA_GREP: ${MOCHA_GREP}
-      LOG_LEVEL: ERROR
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     user: node

+ 4 - 1
services/history-v1/test/acceptance/js/api/backupVerifier.test.mjs

@@ -40,7 +40,10 @@ async function verifyBlobScript(historyId, hash) {
       {
         encoding: 'utf-8',
         timeout: 5_000,
-        env: process.env,
+        env: {
+          ...process.env,
+          LOG_LEVEL: 'warn',
+        },
       }
     )
     return { status: 0, stdout: result.stdout }

+ 2 - 1
services/notifications/docker-compose.yml

@@ -14,6 +14,7 @@ services:
     working_dir: /overleaf/services/notifications
     environment:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit
@@ -31,7 +32,7 @@ services:
       MONGO_HOST: mongo
       POSTGRES_HOST: postgres
       MOCHA_GREP: ${MOCHA_GREP}
-      LOG_LEVEL: ERROR
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     user: node

+ 2 - 1
services/project-history/docker-compose.yml

@@ -14,6 +14,7 @@ services:
     working_dir: /overleaf/services/project-history
     environment:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit
@@ -34,7 +35,7 @@ services:
       MONGO_HOST: mongo
       POSTGRES_HOST: postgres
       MOCHA_GREP: ${MOCHA_GREP}
-      LOG_LEVEL: ERROR
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     user: node

+ 0 - 2
services/project-history/test/acceptance/js/helpers/ProjectHistoryApp.js

@@ -9,8 +9,6 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 import { app } from '../../../../app/js/server.js'
-import logger from '@overleaf/logger'
-logger.logger.level('error')
 
 let running = false
 let initing = false

+ 2 - 1
services/real-time/docker-compose.yml

@@ -14,6 +14,7 @@ services:
     working_dir: /overleaf/services/real-time
     environment:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit
@@ -34,7 +35,7 @@ services:
       MONGO_HOST: mongo
       POSTGRES_HOST: postgres
       MOCHA_GREP: ${MOCHA_GREP}
-      LOG_LEVEL: ERROR
+      LOG_LEVEL: ${LOG_LEVEL:-}
       NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     user: node

+ 1 - 0
services/web/docker-compose.ci.yml

@@ -17,6 +17,7 @@ services:
     environment:
       BASE_CONFIG:
       OVERLEAF_CONFIG:
+      NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     depends_on:
       - mongo

+ 3 - 0
services/web/docker-compose.yml

@@ -17,6 +17,8 @@ services:
       BASE_CONFIG:
       OVERLEAF_CONFIG:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
+      NODE_ENV: test
       NODE_OPTIONS: "--unhandled-rejections=strict"
     command: npm run --silent test:unit:app
     user: node
@@ -36,6 +38,7 @@ services:
       BASE_CONFIG:
       OVERLEAF_CONFIG:
       MOCHA_GREP: ${MOCHA_GREP}
+      LOG_LEVEL: ${LOG_LEVEL:-}
       MONGO_SERVER_SELECTION_TIMEOUT: 600000
       MONGO_SOCKET_TIMEOUT: 300000
       # OVERLEAF_ALLOW_ANONYMOUS_READ_AND_WRITE_SHARING: 'true'

+ 4 - 0
services/web/modules/server-ce-scripts/test/acceptance/src/ServerCEScriptsTests.mjs

@@ -19,6 +19,10 @@ function run(cmd) {
   // Pipe stdin from /dev/null, store stdout, pipe stderr to /dev/null.
   return execSync(cmd, {
     stdio: ['ignore', 'pipe', 'pipe'],
+    env: {
+      ...process.env,
+      LOG_LEVEL: 'warn',
+    },
   }).toString()
 }
 

+ 0 - 3
services/web/test/acceptance/src/helpers/InitApp.mjs

@@ -2,7 +2,6 @@ import App from '../../../../app.mjs'
 import QueueWorkers from '../../../../app/src/infrastructure/QueueWorkers.js'
 import MongoHelper from './MongoHelper.mjs'
 import RedisHelper from './RedisHelper.mjs'
-import logger from '@overleaf/logger'
 import Settings from '@overleaf/settings'
 import MockReCAPTCHAApi from '../mocks/MockReCaptchaApi.mjs'
 import { gracefulShutdown } from '../../../../app/src/infrastructure/GracefulShutdown.js'
@@ -14,8 +13,6 @@ import Modules from '../../../../app/src/infrastructure/Modules.js'
 
 const app = Server.app
 
-logger.logger.level('error')
-
 MongoHelper.initialize()
 RedisHelper.initialize()
 MockReCAPTCHAApi.initialize(2222)