Skip to content

Commit 8fe4b22

Browse files
Merge pull request #49 from shiftcode/#48-injection-token
Replace LogRequestInfoProvider with provider function
2 parents 28f1db3 + 5b6af89 commit 8fe4b22

9 files changed

Lines changed: 51 additions & 22 deletions

File tree

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ Public Angular libraries used in various shiftcode projects.
1111
> ![@shiftcode/ngx-ssr](https://img.shields.io/badge/@shiftcode/ngx--ssr-deprecated-f48700)\
1212
> Not used anymore starting with Angular 17. See necessary changes in [ssr.md](./ssr.md)
1313
14+
> ![@shiftcode/ngx-aws](https://img.shields.io/badge/@shiftcode/ngx--aws-deprecated-f48700)\
15+
> Not used anymore since we refactored how the logging to AWS CloudWatch works. See [Changlog](https://github.com/shiftcode/sc-ng-commons-public/blob/%40shiftcode/ngx-aws%407.0.0/libs/aws/CHANGELOG.md)
16+
> for previous versions.
17+
1418
## Angular to Lib Version Mapping
1519
Shows the mapping between the angular version and our lib versions.
1620

17-
| Angular Version | Lib Version |
18-
|-----------------|-------------|
19-
| `^19` | `^7` |
20-
| `^18` | `^6` |
21-
| `^17` | `^5` |
22-
| `^16` | `^4` |
23-
| `^15` | `^3` |
24-
| `^14` | `^2` |
25-
| `^13` | `^1` |
21+
| Angular Version | Lib Version |
22+
|-----------------|-------------------------------|
23+
| `^19` | `^7 \|\| ^8 \|\| ^9 \|\| ^10` |
24+
| `^18` | `^6` |
25+
| `^17` | `^5` |
26+
| `^16` | `^4` |
27+
| `^15` | `^3` |
28+
| `^14` | `^2` |
29+
| `^13` | `^1` |
2630

2731

2832
## Anatomy of this workspace

libs/components/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shiftcode/ngx-components",
3-
"version": "9.0.0",
3+
"version": "10.0.0-pr48.2",
44
"repository": "https://github.com/shiftcode/sc-ng-commons-public",
55
"license": "MIT",
66
"author": "shiftcode GmbH <team@shiftcode.ch>",
@@ -25,7 +25,7 @@
2525
"@angular/forms": "^19.0.0",
2626
"@angular/router": "^19.0.0",
2727
"@shiftcode/logger": "^3.0.0",
28-
"@shiftcode/ngx-core": "^9.0.0 || ^9.0.0-pr46",
28+
"@shiftcode/ngx-core": "^9.0.0 || ^10.0.0 || ^10.0.0-pr48",
2929
"rxjs": "^6.5.3 || ^7.4.0"
3030
}
3131
}

libs/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shiftcode/ngx-core",
3-
"version": "9.0.0",
3+
"version": "10.0.0-pr48.3",
44
"repository": "https://github.com/shiftcode/sc-ng-commons-public",
55
"license": "MIT",
66
"author": "shiftcode GmbH <team@shiftcode.ch>",

libs/core/src/lib/logger/cloudwatch/cloud-watch.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { CloudWatchLogTransportConfig } from './cloud-watch-log-transport-config
99
import { HttpClient } from '@angular/common/http'
1010
import { isLogStreamNotFoundError } from './is-error.function'
1111
import { ClientIdService } from '../../client-id/client-id.service'
12-
import { LogRequestInfoProvider } from '../log-request-info-provider'
1312
import { RemoteLogData } from '../remote/remote-log-data.model'
13+
import { LOG_REQUEST_INFO } from '../log-request-info.token'
1414

1515
interface CloudWatchLogEvent {
1616
logStreamName: string
@@ -34,7 +34,7 @@ export class CloudWatchService {
3434
private httpClient: HttpClient,
3535
clientIdService: ClientIdService,
3636
@Inject(CLOUD_WATCH_LOG_TRANSPORT_CONFIG) private readonly config: CloudWatchLogTransportConfig,
37-
@Optional() private logRequestInfoProvider?: LogRequestInfoProvider,
37+
@Optional() @Inject(LOG_REQUEST_INFO) private logRequestInfoProvider?: Record<string, string>,
3838
) {
3939
this.clientId = clientIdService.clientId
4040
this.jsonStringifyReplacer = config.jsonStringifyReplacer || jsonMapSetStringifyReplacer
@@ -61,7 +61,7 @@ export class CloudWatchService {
6161

6262
const logDataObject: RemoteLogData = {
6363
...createJsonLogObjectData(level, context, dTimestamp, args),
64-
requestInfo: this.logRequestInfoProvider?.getRequestInfo() ?? {},
64+
requestInfo: this.logRequestInfoProvider ?? {},
6565
}
6666

6767
this.logsSubject.next({

libs/core/src/lib/logger/log-request-info-provider.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { InjectionToken } from '@angular/core'
2+
3+
export const LOG_REQUEST_INFO = new InjectionToken<Record<string, string>>('LOG_REQUEST_INFO')
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { EnvironmentProviders, FactoryProvider, makeEnvironmentProviders, ValueProvider } from '@angular/core'
2+
import { LOG_REQUEST_INFO } from './log-request-info.token'
3+
4+
type LogRequestInfo = Record<string, string | undefined>
5+
6+
export function provideLogRequestInfo(
7+
logRequestInfoOrFactory: LogRequestInfo | (() => LogRequestInfo),
8+
): EnvironmentProviders {
9+
if (typeof logRequestInfoOrFactory === 'function') {
10+
return makeEnvironmentProviders([
11+
{
12+
provide: LOG_REQUEST_INFO,
13+
useFactory: logRequestInfoOrFactory,
14+
} satisfies FactoryProvider,
15+
])
16+
} else {
17+
return makeEnvironmentProviders([
18+
{
19+
provide: LOG_REQUEST_INFO,
20+
useValue: logRequestInfoOrFactory,
21+
} satisfies ValueProvider,
22+
])
23+
}
24+
}

libs/core/src/lib/logger/remote/remote-log.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
import { HttpClient, HttpHeaders } from '@angular/common/http'
33
import { Inject, Injectable, Optional } from '@angular/core'
44
import { createJsonLogObjectData, LogLevel } from '@shiftcode/logger'
5-
import { LogRequestInfoProvider } from '../log-request-info-provider'
65
import { REMOTE_LOG_CONFIG } from './remote-log-config.injection-token'
76
import { RemoteLogConfig } from './remote-log-config.model'
87
import { RemoteLogData } from './remote-log-data.model'
8+
import { LOG_REQUEST_INFO } from '../log-request-info.token'
99

1010
@Injectable({ providedIn: 'root' })
1111
export class RemoteLogService {
1212
protected constructor(
1313
private httpClient: HttpClient,
1414
@Inject(REMOTE_LOG_CONFIG) private config: RemoteLogConfig,
15-
@Optional() private logRequestInfoProvider?: LogRequestInfoProvider,
15+
@Optional() @Inject(LOG_REQUEST_INFO) private logRequestInfoProvider?: Record<string, string>,
1616
) {}
1717

1818
sendMessage(level: LogLevel, context: string, timestamp: Date, args: any[]) {
1919
const remoteLogData: RemoteLogData = {
2020
...createJsonLogObjectData(level, context, timestamp, args),
21-
requestInfo: this.logRequestInfoProvider?.getRequestInfo() ?? {},
21+
requestInfo: this.logRequestInfoProvider ?? {},
2222
}
2323
this.postToBackend(remoteLogData)
2424
}

libs/core/src/public-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export * from './lib/local-storage/local-storage-options'
1313
export * from './lib/local-storage/provide-local-storage'
1414

1515
// logger
16-
export * from './lib/logger/log-request-info-provider'
16+
export * from './lib/logger/log-request-info.token'
17+
export * from './lib/logger/provide-log-request-info'
1718
export * from './lib/logger/logger.service'
1819
export * from './lib/logger/provide-logger'
1920

0 commit comments

Comments
 (0)