diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..c6cd3b6 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,43 @@ +version: 2 +jobs: + + release-snapshot: + docker: + - image: cimg/node:lts + steps: + - checkout + - run: yarn install --frozen-lockfile --non-ineractive + - run: + name: Deploy + command: | + export NPM_TOKEN=${SNAPSHOT_NPM_TOKEN} + npm config set ${NPM_PACKAGE_SCOPE}:registry ${NPM_SNAPSHOT_REPO} + npx semantic-release + release: + docker: + - image: cimg/node:lts + steps: + - checkout + - run: yarn install --frozen-lockfile --non-ineractive + - run: echo "Running release job" + - run: + name: Deploy + command: npx semantic-release + + +workflows: + version: 2 + release: + jobs: + - release-snapshot: + context: Dreamworld + filters: + branches: + only: + - /^feature\/.+$/ + - release: + context: Dreamworld + filters: + branches: + only: + - master \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 8a5f6fa..0000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,70 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '37 17 * * 4' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'javascript' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://git.io/codeql-language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index 4b862ee..0000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,32 +0,0 @@ -# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node.js CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [12.x, 14.x, 16.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm ci - - run: npm run build --if-present - - run: npm test - - run: npm run typings diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml deleted file mode 100644 index e4e4922..0000000 --- a/.github/workflows/npm-publish.yml +++ /dev/null @@ -1,39 +0,0 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a milestone is closed -# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages - -name: Node.js Package - -on: - milestone: - types: [closed] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: 16 - - run: npm ci - - run: npm test - - run: npm run typings - - publish-npm: - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: 16 - registry-url: https://registry.npmjs.org/ - - run: npm ci - - run: | - git config user.name github-actions - git config user.email github-actions@github.com - - run: npm version ${{ github.event.milestone.title }} - - run: git push && git push --tags - - run: npm publish - env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/.gitignore b/.gitignore index ad46b30..2676f60 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,5 @@ typings/ # next.js build output .next + +package-lock.json diff --git a/lib/index.js b/lib/index.js index 504d412..8e7162f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -24,6 +24,19 @@ function format(logData) { return util.format.apply(util, wrapErrorsWithInspect(logData)); } +/** + * Returns index name with given indexPrefix. e.g: `$indexPrefix-yyyymmdd` + * @param {String} indexPrefix + * @returns + */ +function _getIndexName(indexPrefix) { + var date = new Date(); + var yyyy = date.getFullYear(); + var mm = date.getMonth() + 1; + var dd = date.getDate(); + return indexPrefix + String(10000 * yyyy + 100 * mm + dd); +} + /** * * For HTTP (browsers or node.js) use the following configuration params: @@ -52,12 +65,15 @@ function logstashHTTPAppender(config) { const logstashEvent = [ { index: { - _index: config.application, + _index: config.indexPrefix && _getIndexName(config.indexPrefix) || config.application, _type: config.logType, }, }, { + category: event.categoryName, message: format(event.data), + application: config.indexPrefix && config.application || config.application, + instanceId: config.instanceId, context: event.context, level: event.level.level / 100, level_name: event.level.levelStr, diff --git a/package.json b/package.json index 84884cb..a5065fd 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "@log4js-node/logstash-http", - "version": "1.1.0", + "name": "@dreamworld/logstash-http", + "version": "0.0.0-development", "description": "Logstash HTTP Appender for log4js-node", - "homepage": "https://log4js-node.github.io/log4js-node/", + "homepage": "https://github.com/DreamworldSolutions/logstashHTTP", "files": [ "lib", "types" @@ -20,10 +20,10 @@ "author": "Gareth Jones ", "repository": { "type": "git", - "url": "https://github.com/log4js-node/logstashHTTP.git" + "url": "https://github.com/DreamworldSolutions/logstashHTTP.git" }, "bugs": { - "url": "http://github.com/log4js-node/logstashHTTP/issues" + "url": "https://github.com/DreamworldSolutions/logstashHTTP/issues" }, "engines": { "node": ">=6.0" @@ -57,7 +57,8 @@ "nyc": "^11.5.0", "tap": "^12.0.1", "typescript": "^4.7.2", - "validate-commit-msg": "^2.14.0" + "validate-commit-msg": "^2.14.0", + "semantic-release": "17.0.8" }, "browser": { "os": false @@ -91,5 +92,19 @@ "require": [ "./test/sandbox-coverage" ] + }, + "publishConfig": { + "access": "public" + }, + "release": { + "branches": [ + "+([0-9])?(.{+([0-9]),x}).x", + "master", + { + "name": "feature/*", + "prerelease": "${name.replace(/^feature\\//g, \"\")}", + "channel": "${name.replace(/^feature\\//g, \"\")}" + } + ] } }