Skip to content

Commit aff4fa2

Browse files
JunjiequanMoritz Hannemannbpedersen2dependabot[bot]jkotan
authored
feat: integrate gray logger to improve scicat error logging (#965)
* feat: added grayLogger * added unit test for logger service * use inspect to avoid cicular reference error * added grayLog service env variable * use gray logger to log ES initial connection * add gray logger to log Origdatablocks file download * changed wrong test case name * make grayLogger facility variable configurable * removed credentials from logger message * improved error logs integration with grayLogger * fixed unit test failing * renaming customized logger clsas * minor elasticsearch log message change * added flag for gray logger levels * created scicatLogger class to instantiate multiple loggers * defined types for logger methods, cleaned up unnecessary env variables * Fixed props of and added HistoryClass to OpenAPI Schema #941 * Don't fail if es is not enabled and config is missing If es is not enabled, startup fails as values for the related vars are still required. Change-Id: I23cf5ce862bb503eb308bb7e6431fef51edda291 * build(deps): bump @nestjs-modules/mailer from 1.9.1 to 1.10.3 Bumps [@nestjs-modules/mailer](https://github.com/nest-modules/mailer) from 1.9.1 to 1.10.3. - [Release notes](https://github.com/nest-modules/mailer/releases) - [Changelog](https://github.com/nest-modules/mailer/blob/main/CHANGELOG.md) - [Commits](nest-modules/mailer@v1.9.1...v1.10.3) --- updated-dependencies: - dependency-name: "@nestjs-modules/mailer" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump mathjs from 12.2.0 to 12.2.1 Bumps [mathjs](https://github.com/josdejong/mathjs) from 12.2.0 to 12.2.1. - [Changelog](https://github.com/josdejong/mathjs/blob/develop/HISTORY.md) - [Commits](josdejong/mathjs@v12.2.0...v12.2.1) --- updated-dependencies: - dependency-name: mathjs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump openid-client from 5.6.1 to 5.6.2 Bumps [openid-client](https://github.com/panva/node-openid-client) from 5.6.1 to 5.6.2. - [Release notes](https://github.com/panva/node-openid-client/releases) - [Changelog](https://github.com/panva/node-openid-client/blob/main/CHANGELOG.md) - [Commits](panva/openid-client@v5.6.1...v5.6.2) --- updated-dependencies: - dependency-name: openid-client dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @typescript-eslint/parser from 6.14.0 to 6.15.0 Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 6.14.0 to 6.15.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.15.0/packages/parser) --- updated-dependencies: - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump eslint-plugin-prettier from 5.0.1 to 5.1.2 Bumps [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) from 5.0.1 to 5.1.2. - [Release notes](https://github.com/prettier/eslint-plugin-prettier/releases) - [Changelog](https://github.com/prettier/eslint-plugin-prettier/blob/master/CHANGELOG.md) - [Commits](prettier/eslint-plugin-prettier@v5.0.1...v5.1.2) --- updated-dependencies: - dependency-name: eslint-plugin-prettier dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @typescript-eslint/eslint-plugin Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 6.14.0 to 6.15.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.15.0/packages/eslint-plugin) --- updated-dependencies: - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @types/supertest from 2.0.16 to 6.0.1 Bumps [@types/supertest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/supertest) from 2.0.16 to 6.0.1. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/supertest) --- updated-dependencies: - dependency-name: "@types/supertest" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @typescript-eslint/eslint-plugin Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 6.15.0 to 6.16.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.16.0/packages/eslint-plugin) --- updated-dependencies: - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @types/supertest from 6.0.1 to 6.0.2 Bumps [@types/supertest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/supertest) from 6.0.1 to 6.0.2. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/supertest) --- updated-dependencies: - dependency-name: "@types/supertest" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @types/node from 20.10.5 to 20.10.6 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.10.5 to 20.10.6. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump nodemailer from 6.9.7 to 6.9.8 Bumps [nodemailer](https://github.com/nodemailer/nodemailer) from 6.9.7 to 6.9.8. - [Release notes](https://github.com/nodemailer/nodemailer/releases) - [Changelog](https://github.com/nodemailer/nodemailer/blob/master/CHANGELOG.md) - [Commits](nodemailer/nodemailer@v6.9.7...v6.9.8) --- updated-dependencies: - dependency-name: nodemailer dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @types/node-fetch from 2.6.9 to 2.6.10 Bumps [@types/node-fetch](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node-fetch) from 2.6.9 to 2.6.10. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node-fetch) --- updated-dependencies: - dependency-name: "@types/node-fetch" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @typescript-eslint/parser from 6.15.0 to 6.16.0 Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 6.15.0 to 6.16.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.16.0/packages/parser) --- updated-dependencies: - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * workaround for wrong degC to K conversion * build(deps-dev): bump @typescript-eslint/eslint-plugin Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 6.16.0 to 6.18.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.18.0/packages/eslint-plugin) --- updated-dependencies: - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @types/luxon from 3.3.7 to 3.4.0 Bumps [@types/luxon](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/luxon) from 3.3.7 to 3.4.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/luxon) --- updated-dependencies: - dependency-name: "@types/luxon" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump openid-client from 5.6.2 to 5.6.4 Bumps [openid-client](https://github.com/panva/node-openid-client) from 5.6.2 to 5.6.4. - [Release notes](https://github.com/panva/node-openid-client/releases) - [Changelog](https://github.com/panva/node-openid-client/blob/main/CHANGELOG.md) - [Commits](panva/openid-client@v5.6.2...v5.6.4) --- updated-dependencies: - dependency-name: openid-client dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @typescript-eslint/parser from 6.16.0 to 6.18.0 Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 6.16.0 to 6.18.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.18.0/packages/parser) --- updated-dependencies: - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @nestjs/schematics from 10.0.3 to 10.1.0 Bumps [@nestjs/schematics](https://github.com/nestjs/schematics) from 10.0.3 to 10.1.0. - [Release notes](https://github.com/nestjs/schematics/releases) - [Changelog](https://github.com/nestjs/schematics/blob/master/.release-it.json) - [Commits](nestjs/schematics@10.0.3...10.1.0) --- updated-dependencies: - dependency-name: "@nestjs/schematics" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @types/node from 20.10.6 to 20.10.7 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.10.6 to 20.10.7. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @nestjs/cli from 10.2.1 to 10.3.0 Bumps [@nestjs/cli](https://github.com/nestjs/nest-cli) from 10.2.1 to 10.3.0. - [Release notes](https://github.com/nestjs/nest-cli/releases) - [Changelog](https://github.com/nestjs/nest-cli/blob/master/.release-it.json) - [Commits](nestjs/nest-cli@10.2.1...10.3.0) --- updated-dependencies: - dependency-name: "@nestjs/cli" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps-dev): bump @types/passport-jwt from 3.0.13 to 4.0.0 Bumps [@types/passport-jwt](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/passport-jwt) from 3.0.13 to 4.0.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/passport-jwt) --- updated-dependencies: - dependency-name: "@types/passport-jwt" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * build(deps): bump follow-redirects from 1.15.2 to 1.15.4 Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.2 to 1.15.4. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](follow-redirects/follow-redirects@v1.15.2...v1.15.4) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * added endpoint and related tests * addedd output dtos and updated swagger interface for users * fixed linting issues * fixed linting issue * changes based on comments * fix logger service unit test * change jsonconfig to be more generic * typo fix --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Moritz Hannemann <[email protected]> Co-authored-by: Björn Pedersen <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jan Kotanski <[email protected]> Co-authored-by: Max Novelli <[email protected]>
1 parent 4997d4e commit aff4fa2

17 files changed

+358
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/dist
33
/node_modules
44
functionalAccounts.json
5+
loggers.json
56

67
# Configs
78
.env

loggers.json.example

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"type": "DefaultLogger",
4+
"modulePath": "./loggingProviders/defaultLogger",
5+
"config": {}
6+
},
7+
{
8+
"type": "GrayLogger",
9+
"modulePath": "./loggingProviders/grayLogger",
10+
"config": {
11+
"facility": "scicatOfficial",
12+
"environment": "test",
13+
"server": "localhost",
14+
"service": "scicat-backend-next",
15+
"port": 9999
16+
}
17+
}
18+
]

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@nestjs/platform-express": "^9.0.0",
4646
"@nestjs/swagger": "^7.1.7",
4747
"@nestjs/terminus": "^10.1.1",
48+
"@user-office-software/duo-logger": "^2.1.1",
4849
"@user-office-software/duo-message-broker": "^1.4.0",
4950
"bcrypt": "^5.1.0",
5051
"class-transformer": "^0.5.1",

src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { CommonModule } from "./common/common.module";
3131
import { EventEmitterModule } from "@nestjs/event-emitter";
3232
import { AdminModule } from "./admin/admin.module";
3333
import { HealthModule } from "./health/health.module";
34+
import { LoggerModule } from "./loggers/logger.module";
3435

3536
@Module({
3637
imports: [
@@ -41,6 +42,7 @@ import { HealthModule } from "./health/health.module";
4142
ConfigModule.forRoot({
4243
load: [configuration],
4344
}),
45+
LoggerModule,
4446
DatablocksModule,
4547
DatasetsModule,
4648
InitialDatasetsModule,

src/common/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/quotes */
22
import { Logger } from "@nestjs/common";
3+
import { inspect } from "util";
34
import { DateTime } from "luxon";
45
import { format, unit } from "mathjs";
56
import { Expression, FilterQuery, Model, PipelineStage } from "mongoose";
@@ -211,7 +212,9 @@ export const handleAxiosRequestError = (
211212
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
212213
// http.ClientRequest in node.js
213214
console.error(error.request);
214-
Logger.error({ request: error.request }, context);
215+
216+
// Inspect is needed to deal with circular references issue.
217+
Logger.error({ request: inspect(error.request) }, context);
215218
} else {
216219
// Something happened in setting up the request that triggered an Error
217220
Logger.error("Error: " + error.message, context);

src/config/configuration.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Logger } from "@nestjs/common";
1+
import * as fs from "fs";
22

33
const configuration = () => {
44
const accessGroupsStaticValues =
@@ -22,10 +22,34 @@ const configuration = () => {
2222
const proposalGroups = process.env.PROPOSAL_GROUPS || ("" as string);
2323
const sampleGroups = process.env.SAMPLE_GROUPS || ("" as string);
2424

25+
const defaultLogger = {
26+
type: "DefaultLogger",
27+
modulePath: "./loggingProviders/defaultLogger",
28+
config: {},
29+
};
30+
const jsonConfigMap: { [key: string]: object[] | boolean } = {};
31+
const jsonConfigFileList: { [key: string]: string } = {
32+
loggers: process.env.LOGGERS_CONFIG_FILE || "loggers.json",
33+
};
34+
Object.keys(jsonConfigFileList).forEach((key) => {
35+
const filePath = jsonConfigFileList[key];
36+
if (fs.existsSync(filePath)) {
37+
const data = fs.readFileSync(filePath, "utf8");
38+
try {
39+
jsonConfigMap[key] = JSON.parse(data);
40+
} catch (error) {
41+
console.error(
42+
"Error json config file parsing " + filePath + " : " + error,
43+
);
44+
jsonConfigMap[key] = false;
45+
}
46+
}
47+
});
48+
2549
// Logger.log("Config SETUP");
2650
// Logger.log("- Access groups statisc values : " + accessGroupsStaticValues);
2751
// Logger.log("- Admin groups : " + adminGroups);
28-
// Logger.log("- Delete groups : " + deleteGroups);
52+
// Logger.log("- Delete groups : " + deleteGroups );
2953
// Logger.log("- Create dataset groups : " + createDatasetGroups);
3054
// Logger.log(
3155
// "- Create dataset with pid groups : " + createDatasetWithPidGroups,
@@ -37,6 +61,7 @@ const configuration = () => {
3761
// Logger.log("- Update job groups : " + updateJobGroups);
3862

3963
return {
64+
loggerConfigs: jsonConfigMap.loggers || [defaultLogger],
4065
adminGroups: adminGroups.split(",").map((v) => v.trim()) ?? [],
4166
deleteGroups: deleteGroups.split(",").map((v) => v.trim()) ?? [],
4267
createDatasetGroups: createDatasetGroups.split(",").map((v) => v.trim()),
@@ -81,6 +106,7 @@ const configuration = () => {
81106
usernameAttr: process.env.LDAP_USERNAME ?? "displayName",
82107
},
83108
},
109+
84110
oidc: {
85111
issuer: process.env.OIDC_ISSUER, // Example: https://identity.esss.dk/realm/ess
86112
clientID: process.env.OIDC_CLIENT_ID, // Example: scicat
@@ -101,6 +127,7 @@ const configuration = () => {
101127
baseUrl:
102128
process.env.LOGBOOK_BASE_URL ?? "http://localhost:3030/scichatapi",
103129
},
130+
104131
metadataKeysReturnLimit: process.env.METADATA_KEYS_RETURN_LIMIT
105132
? parseInt(process.env.METADATA_KEYS_RETURN_LIMIT, 10)
106133
: undefined,

src/elastic-search/elastic-search.service.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class ElasticSearchService implements OnModuleInit {
7171
) {
7272
Logger.error(
7373
"Missing ENVIRONMENT variables for elastic search connection",
74+
"ElasticSearch",
7475
);
7576
}
7677
}
@@ -88,9 +89,9 @@ export class ElasticSearchService implements OnModuleInit {
8889
await this.createIndex(this.defaultIndex);
8990
}
9091
this.connected = true;
91-
Logger.log("Elasticsearch Connected");
92+
Logger.log("Elasticsearch Connected", "ElasticSearch");
9293
} catch (error) {
93-
Logger.error("onModuleInit failed-> ElasticSearchService", error);
94+
Logger.error(error, "onModuleInit failed-> ElasticSearchService");
9495
}
9596
}
9697

@@ -161,10 +162,12 @@ export class ElasticSearchService implements OnModuleInit {
161162
await this.esService.indices.open({
162163
index,
163164
});
164-
Logger.log(`Elasticsearch Index Created-> Index: ${index}`);
165+
Logger.log(
166+
`Elasticsearch Index Created-> Index: ${index}`,
167+
"Elasticsearch",
168+
);
165169
return HttpStatus.CREATED;
166170
} catch (error) {
167-
Logger.error("createIndex failed-> ElasticSearchService", error);
168171
throw new HttpException(
169172
`createIndex failed-> ElasticSearchService ${error}`,
170173
HttpStatus.BAD_REQUEST,
@@ -191,7 +194,6 @@ export class ElasticSearchService implements OnModuleInit {
191194
try {
192195
return await this.esService.count({ index });
193196
} catch (error) {
194-
Logger.error("getCount failed-> ElasticSearchService", error);
195197
throw new HttpException(
196198
`getCount failed-> ElasticSearchService ${error}`,
197199
HttpStatus.BAD_REQUEST,
@@ -221,9 +223,11 @@ export class ElasticSearchService implements OnModuleInit {
221223
await this.esService.indices.open({
222224
index,
223225
});
224-
Logger.log(`Elasticsearch Index Updated-> Index: ${index}`);
226+
Logger.log(
227+
`Elasticsearch Index Updated-> Index: ${index}`,
228+
"Elasticsearch",
229+
);
225230
} catch (error) {
226-
Logger.error("updateIndex failed-> ElasticSearchService", error);
227231
throw new HttpException(
228232
`updateIndex failed-> ElasticSearchService ${error}`,
229233
HttpStatus.BAD_REQUEST,
@@ -235,7 +239,6 @@ export class ElasticSearchService implements OnModuleInit {
235239
try {
236240
return await this.esService.indices.getSettings({ index });
237241
} catch (error) {
238-
Logger.error("getIndexSettings failed-> ElasticSearchService", error);
239242
throw new HttpException(
240243
`getIndexSettings failed-> ElasticSearchService ${error}`,
241244
HttpStatus.BAD_REQUEST,
@@ -246,10 +249,12 @@ export class ElasticSearchService implements OnModuleInit {
246249
async deleteIndex(index = this.defaultIndex) {
247250
try {
248251
await this.esService.indices.delete({ index });
249-
Logger.log(`Elasticsearch Index Deleted-> Index: ${index} `);
252+
Logger.log(
253+
`Elasticsearch Index Deleted-> Index: ${index} `,
254+
"Elasticsearch",
255+
);
250256
return { success: true, message: `Index ${index} deleted` };
251257
} catch (error) {
252-
Logger.error("deleteIndex failed-> ElasticSearchService", error);
253258
throw new HttpException(
254259
`deleteIndex failed-> ElasticSearchService ${error}`,
255260
HttpStatus.BAD_REQUEST,
@@ -323,8 +328,6 @@ export class ElasticSearchService implements OnModuleInit {
323328
data,
324329
};
325330
} catch (error) {
326-
Logger.error("SearchService || search query issue || -> search", error);
327-
328331
throw new HttpException(
329332
`SearchService || search query issue || -> search ${error}`,
330333
HttpStatus.BAD_REQUEST,
@@ -352,11 +355,6 @@ export class ElasticSearchService implements OnModuleInit {
352355

353356
return transformedFacets;
354357
} catch (error) {
355-
Logger.error(
356-
"SearchService || aggregate query issue || -> aggregate",
357-
error,
358-
);
359-
360358
throw new HttpException(
361359
`SearchService || aggregate query issue || -> aggregate ${error}`,
362360
HttpStatus.BAD_REQUEST,
@@ -383,10 +381,14 @@ export class ElasticSearchService implements OnModuleInit {
383381
});
384382

385383
Logger.log(
386-
`Elasticsearch Document Update/inserted-> Document_id: ${data.pid} update/inserted on index: ${this.defaultIndex}`,
384+
`Document Update/inserted-> Document_id: ${data.pid} update/inserted on index: ${this.defaultIndex}`,
385+
"Elasticsearch",
387386
);
388387
} catch (error) {
389-
Logger.error("updateDocument failed-> ElasticSearchService", error);
388+
throw new HttpException(
389+
`updateDocument failed-> ElasticSearchService ${error}`,
390+
HttpStatus.BAD_REQUEST,
391+
);
390392
}
391393
}
392394

@@ -398,10 +400,14 @@ export class ElasticSearchService implements OnModuleInit {
398400
refresh: this.refresh,
399401
});
400402
Logger.log(
401-
`Elasticsearch Document Deleted-> Document_id: ${id} deleted on index: ${this.defaultIndex}`,
403+
`Document Deleted-> Document_id: ${id} deleted on index: ${this.defaultIndex}`,
404+
"Elasticsearch",
402405
);
403406
} catch (error) {
404-
Logger.error("deleteDocument failed-> ElasticSearchService", error);
407+
throw new HttpException(
408+
`deleteDocument failed-> ElasticSearchService ${error}`,
409+
HttpStatus.BAD_REQUEST,
410+
);
405411
}
406412
}
407413

@@ -424,11 +430,7 @@ export class ElasticSearchService implements OnModuleInit {
424430
];
425431
},
426432
onDrop(doc) {
427-
console.error(doc.document._id, doc.error?.reason);
428-
Logger.error(
429-
"SearchService-> performBulkOperation-> data insert faield: ",
430-
doc.document._id,
431-
);
433+
console.debug(`${doc.document._id}`, doc.error?.reason);
432434
},
433435
});
434436
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface GrayLoggerConfig {
2+
server: string;
3+
port: number;
4+
facility: string;
5+
environment: string;
6+
service: string;
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export interface Logger {
2+
log(message: string, context: Record<string, unknown>): void;
3+
error(message: string, context: Record<string, unknown>): void;
4+
warn(message: string, context: Record<string, unknown>): void;
5+
debug(message: string, context: Record<string, unknown>): void;
6+
exception(
7+
message: string,
8+
exception: unknown,
9+
context: Record<string, unknown>,
10+
): void;
11+
}
12+
13+
export interface LoggerConfig {
14+
type: string;
15+
modulePath: string;
16+
config?: Record<string, unknown>;
17+
}

0 commit comments

Comments
 (0)