Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ runs:
using: "composite"
steps:
- name: Cache dependencies
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.node-version }}
cache: ${{ env.node-package-manager }}
22 changes: 11 additions & 11 deletions .github/workflows/node-ci.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: ./.github/actions/cache
- name: Install dependencies
run: yarn install --frozen-lockfile
Expand All @@ -29,14 +29,14 @@ jobs:
needs: cache-dependencies
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: ./.github/actions/test

validate-dependencies:
runs-on: ubuntu-latest
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: ./.github/actions/validate-dependencies

build:
Expand All @@ -46,7 +46,7 @@ jobs:
- validate-dependencies
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: ./.github/actions/cache

- name: Install dependencies
Expand All @@ -56,7 +56,7 @@ jobs:
run: yarn build

- name: Upload build artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-develop
path: dist
Expand All @@ -68,7 +68,7 @@ jobs:
defined: ${{ steps.username.outputs.defined == 'true' && steps.password.outputs.defined == 'true' }}
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check if has username
id: username
Expand All @@ -89,7 +89,7 @@ jobs:
- check-docker-credentials
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: get version
id: version
Expand All @@ -98,27 +98,27 @@ jobs:
path: 'package.json'
prop_path: 'version'

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}-develop
path: dist

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
images: "tv2media/${{ github.event.repository.name }}"
tags: |
type=ref,event=branch

- name: Log in to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
46 changes: 23 additions & 23 deletions .github/workflows/node-ci.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: ./.github/actions/cache
- name: Install dependencies
run: yarn install --frozen-lockfile
Expand All @@ -44,7 +44,7 @@ jobs:
needs: cache-dependencies
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: ./.github/actions/cache
- name: Install dependencies
run: yarn install --frozen-lockfile
Expand All @@ -56,15 +56,15 @@ jobs:
needs: cache-dependencies
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: ./.github/actions/test

validate-dependencies:
runs-on: ubuntu-latest
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: ./.github/actions/validate-dependencies

bump-version:
Expand All @@ -80,20 +80,20 @@ jobs:
bumped: ${{ steps.tag_version.outputs.new_tag != '' }}
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Configure committer
run: |
git config user.name "${{ github.event.pusher.name }}"
git config user.email "${{ github.event.pusher.email }}"
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v5.6
uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
- name: Update package.json
if: steps.tag_version.outputs.new_tag != ''
uses: jossef/action-set-json-field@v1
uses: jossef/action-set-json-field@v2.1
with:
file: package.json
field: version
Expand All @@ -108,7 +108,7 @@ jobs:

- name: Commit and push changes to package.json and CHANGELOG.md
if: steps.tag_version.outputs.new_tag != ''
uses: EndBug/add-and-commit@v7
uses: EndBug/add-and-commit@v9
with:
add: "['package.json', 'CHANGELOG.md']"

Expand All @@ -119,7 +119,7 @@ jobs:
- bump-version
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Pull request to develop
id: develop
continue-on-error: true
Expand All @@ -140,7 +140,7 @@ jobs:
- bump-version
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Ensure commits from bump-version
run: git pull
- uses: ./.github/actions/cache
Expand All @@ -149,7 +149,7 @@ jobs:
- name: Build
run: yarn build
- name: Upload build artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: dist
Expand All @@ -161,7 +161,7 @@ jobs:
defined: ${{ steps.release.outputs.defined == 'true' }}
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Check if is set to release
id: release
uses: ./.github/actions/check-secret
Expand All @@ -176,9 +176,9 @@ jobs:
- check-github-release
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: dist
Expand Down Expand Up @@ -213,7 +213,7 @@ jobs:
defined: ${{ steps.token.outputs.defined == 'true' }}
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Check if has username
id: token
uses: ./.github/actions/check-secret
Expand All @@ -228,17 +228,17 @@ jobs:
- check-npm-token
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Configure publisher
run: |
git config user.name "${{ github.event.pusher.name }}"
git config user.email "${{ github.event.pusher.email }}"
- name: Download artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: dist
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"
Expand All @@ -259,7 +259,7 @@ jobs:
defined: ${{ steps.username.outputs.defined == 'true' && steps.password.outputs.defined == 'true' }}
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Check if has username
id: username
uses: ./.github/actions/check-secret
Expand All @@ -279,9 +279,9 @@ jobs:
- check-docker-credentials
steps:
- name: Access repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: dist
Expand All @@ -293,13 +293,13 @@ jobs:
version: ${{ needs.bump-version.outputs.version }}

- name: Log in to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
"email": "[email protected]"
},
"devDependencies": {
"@types/jest": "^29.2.5",
"@types/jest": "^29.5.14",
"@types/node": "^18.13.0",
"@typescript-eslint/eslint-plugin": "^5.48.1",
"@typescript-eslint/parser": "^5.48.1",
"eslint": "^8.34.0",
"jest": "^29.4.3",
"ts-jest": "^29.0.4",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"ts-mockito": "^2.6.1",
"typescript": "^4.9.4"
}
}
}
28 changes: 28 additions & 0 deletions src/formats/json.format.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { JsonFormat, JsonFormatOptions } from './json.format'
import { Log } from '../log'
import { Level } from '../level'

describe('JsonFormat', () => {
describe('when log has timestamp set to epoch timestamp', () => {
it('it includes the timestamp attribute formatted as ISO-8601 with UTC timezone', () => {
const timestamp = 1731912859428
const log: Log = {
level: Level.INFO,
message: '',
timestamp,
}
const testee: JsonFormat = createTestee()

const result: string = testee.apply(log)

expect(result).toMatch('"timestamp":"2024-11-18T06:54:19.428Z"')
})
})
})

function createTestee(options: Partial<JsonFormatOptions> = {}): JsonFormat {
return new JsonFormat({
isPretty: false,
...options,
})
}
21 changes: 19 additions & 2 deletions src/formats/json.format.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Format } from '../format'
import { Log } from '../log'
import { JsonEncoder } from '../services/json-encoder'
import { DateFormatter } from '../services/date-formatter'
import { IsoDateFormatter } from '../services/iso-date-formatter'

export interface JsonFormatOptions {
isPretty: boolean
Expand All @@ -9,14 +11,29 @@ export interface JsonFormatOptions {
export class JsonFormat extends Format {

private readonly jsonEncoder: JsonEncoder
private readonly dateFormatter: DateFormatter

constructor(options: JsonFormatOptions) {
super()
this.jsonEncoder = new JsonEncoder(options)
this.dateFormatter = new IsoDateFormatter()
}

apply(log: Log): string {
return this.jsonEncoder.encode(log)
public apply(log: Log): string {
return this.jsonEncoder.encode({
...log,
timestamp: this.getFormattedTimestamp(log.timestamp)
})
}

private getFormattedTimestamp(timestamp: unknown): string {
if (typeof timestamp === 'number') {
return this.dateFormatter.formatTimestamp(timestamp)
}
if (!timestamp) {
return this.dateFormatter.formatTimestamp(Date.now())
}
return `${timestamp}`
}

}
10 changes: 7 additions & 3 deletions src/formats/plain-text.format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ export class PlainTextFormat extends Format {
}

protected getTimestamp(log: Log): string {
const timestamp = log.timestamp ?? Date.now()
const formattedTimestamp = this.dateFormatter.formatTimestamp(timestamp)
return `[${ formattedTimestamp }]`
if (typeof log.timestamp === 'number') {
return `[${this.dateFormatter.formatTimestamp(log.timestamp)}]`
}
if (!log.timestamp) {
return `[${this.dateFormatter.formatTimestamp(Date.now())}]`
}
return `[${ log.timestamp }]`
}

protected getSeverity(log: Log): string {
Expand Down
Loading
Loading