diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index 7ef19339..0be1bc3b 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -125,6 +125,8 @@ jobs: SERVER_SENTRY_DSN=${{ secrets.SERVER_SENTRY_DSN }} AWS_ACCESS_KEY_ID=${{ secrets.SERVER_AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY=${{ secrets.SERVER_AWS_SECRET_ACCESS_KEY }} + SERVER_CORALOGIX_SERVICE_NAME=${{ vars.SERVER_CORALOGIX_SERVICE_NAME }} + SERVER_CORALOGIX_API_KEY=${{secrets.SERVER_CORALOGIX_API_KEY}} VERSION=${{github.sha}} NODE_ENV=staging - name: Deploy Amazon ECS task definition @@ -174,6 +176,8 @@ jobs: VERSION=${{github.sha}} AWS_ACCESS_KEY_ID=${{ secrets.SERVER_AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY=${{ secrets.SERVER_AWS_SECRET_ACCESS_KEY }} + SERVER_CORALOGIX_SERVICE_NAME=${{ vars.SERVER_CORALOGIX_SERVICE_NAME }} + SERVER_CORALOGIX_API_KEY=${{secrets.SERVER_CORALOGIX_API_KEY}} NODE_ENV=production - name: Deploy Amazon ECS task definition uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..556fec0f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "meirim", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/server/api/lib/log.js b/server/api/lib/log.js index 5d4b6513..f8e5c565 100644 --- a/server/api/lib/log.js +++ b/server/api/lib/log.js @@ -1,31 +1,49 @@ const winston = require('winston'); +const os = require('os'); +const Config = require('./config'); + +const apikey = Config.get('coralogix.apikey'); +const serviceName = Config.get('coralogix.serviceName'); +const host = Config.get('coralogix.host'); + const logger = winston.createLogger({ level: 'info', format: winston.format.json(), - defaultMeta: { service: 'user-service' }, + defaultMeta: { version: process.env.VERSION, env: process.env.NODE_ENV }, transports: [ - new winston.transports.Console() - // - // - Write to all logs with level `info` and below to `combined.log` - // - Write all logs error (and below) to `error.log`. - // - // new winston.transports.File({ filename: 'error.log', level: 'error' }), - // new winston.transports.File({ filename: 'combined.log' }) + new winston.transports.Console(), + new winston.transports.Http({ + name: "coralogix", + level: "info", + format: winston.format((info) => ({ + applicationName: "meirim", + subsystemName: serviceName, + computerName: os.hostname(), + timestamp: Date.now(), + severity: { + silly: 1, + debug: 1, + verbose: 2, + info: 3, + warn: 4, + error: 5, + critical: 6 + }[info.level] || 3, + text: info.message, + }))(), + host: host, + path: "logs/v1/singles", + headers: { + "authorization": "Bearer " + apikey, + }, + ssl: true, + batchInterval: 1000, + handleExceptions: true, + }), ] }); -// -// If we're not in production then log to the `console` with the format: -// `${info.level}: ${info.message} JSON.stringify({ ...rest }) ` -// // -// if (process.env.NODE_ENV !== 'production') { -// logger.add(new winston.transports.Console({ -// format: winston.format.simple() -// })); -// } - -logger.level = 'debug'; module.exports = { debug: (...args) => { diff --git a/server/bin/serve b/server/bin/serve index 2888694c..a9652c57 100644 --- a/server/bin/serve +++ b/server/bin/serve @@ -73,6 +73,8 @@ server.on('error', (error) => { server.on('listening', () => { const addr = server.address(); const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; + + l.info("this is a test!") console.log('Listening on ' + bind); }); diff --git a/server/config/custom-environment-variables.json b/server/config/custom-environment-variables.json index 10d9dcc8..1e2b5661 100644 --- a/server/config/custom-environment-variables.json +++ b/server/config/custom-environment-variables.json @@ -1,4 +1,5 @@ { + "coralogix": {"apikey": "SERVER_CORALOGIX_API_KEY", "serviceName": "SERVER_CORALOGIX_SERVICE_NAME"}, "sentry_dsn": "SERVER_SENTRY_DSN", "geocoder": { "apiKey": "SERVER_GEOCODER_API_KEY" diff --git a/server/config/default.json b/server/config/default.json index 2071b2a4..87034ea2 100644 --- a/server/config/default.json +++ b/server/config/default.json @@ -1,4 +1,7 @@ { + "coralogix": { + "host": "ingress.cx498.coralogix.com" + }, "geocoder": { "provider": "google", "httpAdapter": "https", diff --git a/server/package-lock.json b/server/package-lock.json index 55cce33e..e4c9bc55 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -63,7 +63,7 @@ "staticmaps": "^1.10.0", "terraformer-wkt-parser": "^1.2.1", "turf": "^3.0.14", - "winston": "^3.3.3", + "winston": "^3.10.3", "xlsx": "^0.16.9" }, "devDependencies": { @@ -835,6 +835,14 @@ "node": ">=6.9.0" } }, + "node_modules/@colors/colors": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.6.0.tgz", + "integrity": "sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==", + "engines": { + "node": ">=0.1.90" + } + }, "node_modules/@dabh/diagnostics": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@dabh/diagnostics/-/diagnostics-2.0.2.tgz", @@ -2016,6 +2024,11 @@ "@types/node": "*" } }, + "node_modules/@types/triple-beam": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.5.tgz", + "integrity": "sha512-6WaYesThRMCl19iryMYP7/x2OVgCtbIVflDGFpWnb9irXI3UjYE4AzmYuiUKY1AJstGijoY+MgUszMgRxIYTYw==" + }, "node_modules/@types/yauzl": { "version": "2.9.1", "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.1.tgz", @@ -3978,14 +3991,6 @@ "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.1.tgz", "integrity": "sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==" }, - "node_modules/colors": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", - "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", - "engines": { - "node": ">=0.1.90" - } - }, "node_modules/colorspace": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/colorspace/-/colorspace-1.1.2.tgz", @@ -6127,11 +6132,6 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, - "node_modules/fast-safe-stringify": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz", - "integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==" - }, "node_modules/fast-xml-parser": { "version": "4.2.5", "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.2.5.tgz", @@ -6167,9 +6167,9 @@ } }, "node_modules/fecha": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.0.tgz", - "integrity": "sha512-aN3pcx/DSmtyoovUudctc8+6Hl4T+hI9GBBHLjA76jdZl7+b1sgh5g4k+u/GL3dTy1/pnYzKp69FpJ0OicE3Wg==" + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", + "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==" }, "node_modules/fflate": { "version": "0.3.10", @@ -8499,15 +8499,19 @@ } }, "node_modules/logform": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/logform/-/logform-2.2.0.tgz", - "integrity": "sha512-N0qPlqfypFx7UHNn4B3lzS/b0uLqt2hmuoa+PpuXNYgozdJYAyauF5Ky0BWVjrxDlMWiT3qN4zPq3vVAfZy7Yg==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.6.0.tgz", + "integrity": "sha512-1ulHeNPp6k/LD8H91o7VYFBng5i1BDE7HoKxVbZiGFidS1Rj65qcywLxX+pVfAPoQJEjRdvKcusKwOupHCVOVQ==", "dependencies": { - "colors": "^1.2.1", - "fast-safe-stringify": "^2.0.4", + "@colors/colors": "1.6.0", + "@types/triple-beam": "^1.3.2", "fecha": "^4.2.0", "ms": "^2.1.1", + "safe-stable-stringify": "^2.3.1", "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" } }, "node_modules/loose-envify": { @@ -14499,6 +14503,14 @@ "ret": "~0.1.10" } }, + "node_modules/safe-stable-stringify": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz", + "integrity": "sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==", + "engines": { + "node": ">=10" + } + }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -15997,9 +16009,12 @@ "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, "node_modules/triple-beam": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", - "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.4.1.tgz", + "integrity": "sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==", + "engines": { + "node": ">= 14.0.0" + } }, "node_modules/tsconfig-paths": { "version": "3.9.0", @@ -17349,40 +17364,56 @@ } }, "node_modules/winston": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/winston/-/winston-3.3.3.tgz", - "integrity": "sha512-oEXTISQnC8VlSAKf1KYSSd7J6IWuRPQqDdo8eoRNaYKLvwSb5+79Z3Yi1lrl6KDpU6/VWaxpakDAtb1oQ4n9aw==", + "version": "3.11.0", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.11.0.tgz", + "integrity": "sha512-L3yR6/MzZAOl0DsysUXHVjOwv8mKZ71TrA/41EIduGpOOV5LQVodqN+QdQ6BS6PJ/RdIshZhq84P/fStEZkk7g==", "dependencies": { + "@colors/colors": "^1.6.0", "@dabh/diagnostics": "^2.0.2", - "async": "^3.1.0", + "async": "^3.2.3", "is-stream": "^2.0.0", - "logform": "^2.2.0", + "logform": "^2.4.0", "one-time": "^1.0.0", "readable-stream": "^3.4.0", + "safe-stable-stringify": "^2.3.1", "stack-trace": "0.0.x", "triple-beam": "^1.3.0", - "winston-transport": "^4.4.0" + "winston-transport": "^4.5.0" }, "engines": { - "node": ">= 6.4.0" + "node": ">= 12.0.0" } }, "node_modules/winston-transport": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.4.0.tgz", - "integrity": "sha512-Lc7/p3GtqtqPBYYtS6KCN3c77/2QCev51DvcJKbkFPQNoj1sinkGwLGFDxkXY9J6p9+EPnYs+D90uwbnaiURTw==", + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.7.0.tgz", + "integrity": "sha512-ajBj65K5I7denzer2IYW6+2bNIVqLGDHqDw3Ow8Ohh+vdW+rv4MZ6eiDvHoKhfJFZ2auyN8byXieDDJ96ViONg==", + "dependencies": { + "logform": "^2.3.2", + "readable-stream": "^3.6.0", + "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, + "node_modules/winston-transport/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", "dependencies": { - "readable-stream": "^2.3.7", - "triple-beam": "^1.2.0" + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" }, "engines": { - "node": ">= 6.4.0" + "node": ">= 6" } }, "node_modules/winston/node_modules/async": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", - "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz", + "integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==" }, "node_modules/winston/node_modules/readable-stream": { "version": "3.6.0", diff --git a/server/package.json b/server/package.json index e5d38138..95b05c4f 100644 --- a/server/package.json +++ b/server/package.json @@ -68,7 +68,7 @@ "staticmaps": "^1.10.0", "terraformer-wkt-parser": "^1.2.1", "turf": "^3.0.14", - "winston": "^3.3.3", + "winston": "^3.10.3", "xlsx": "^0.16.9" }, "scripts": {