Skip to content

Commit

Permalink
deafult typesense logger, error, only
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ocean committed Jul 16, 2024
1 parent 4bdf70a commit 0437247
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
18 changes: 12 additions & 6 deletions src/components/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class OrderDatabase {
return (async (): Promise<OrderDatabase> => {
this.provider = new Typesense({
...convertTypesenseConfig(this.config.url),
logger: DATABASE_LOGGER
logger: DATABASE_LOGGER,
logLevel: LOG_LEVELS_STR.LEVEL_ERROR
})
try {
await this.provider.collections(this.schema.name).retrieve()
Expand Down Expand Up @@ -191,7 +192,8 @@ export class DdoStateDatabase {
return (async (): Promise<DdoStateDatabase> => {
this.provider = new Typesense({
...convertTypesenseConfig(this.config.url),
logger: DATABASE_LOGGER
logger: DATABASE_LOGGER,
logLevel: LOG_LEVELS_STR.LEVEL_ERROR
})
try {
await this.provider.collections(this.schema.name).retrieve()
Expand Down Expand Up @@ -327,7 +329,8 @@ export class DdoDatabase {
return (async (): Promise<DdoDatabase> => {
this.provider = new Typesense({
...convertTypesenseConfig(this.config.url),
logger: DATABASE_LOGGER
logger: DATABASE_LOGGER,
logLevel: LOG_LEVELS_STR.LEVEL_ERROR
})
for (const ddoSchema of this.schemas) {
try {
Expand Down Expand Up @@ -617,7 +620,8 @@ export class NonceDatabase {
return (async (): Promise<NonceDatabase> => {
this.provider = new Typesense({
...convertTypesenseConfig(this.config.url),
logger: DATABASE_LOGGER
logger: DATABASE_LOGGER,
logLevel: LOG_LEVELS_STR.LEVEL_ERROR
})
try {
await this.provider.collections(this.schema.name).retrieve()
Expand Down Expand Up @@ -722,7 +726,8 @@ export class IndexerDatabase {
return (async (): Promise<IndexerDatabase> => {
this.provider = new Typesense({
...convertTypesenseConfig(this.config.url),
logger: DATABASE_LOGGER
logger: DATABASE_LOGGER,
logLevel: LOG_LEVELS_STR.LEVEL_ERROR
})
try {
await this.provider.collections(this.schema.name).retrieve()
Expand Down Expand Up @@ -832,7 +837,8 @@ export class LogDatabase {
return (async (): Promise<LogDatabase> => {
this.provider = new Typesense({
...convertTypesenseConfig(this.config.url),
logger: DATABASE_LOGGER
logger: DATABASE_LOGGER,
logLevel: LOG_LEVELS_STR.LEVEL_ERROR
})
try {
await this.provider.collections(this.schema.name).retrieve()
Expand Down
7 changes: 1 addition & 6 deletions src/test/integration/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
CustomNodeLogger,
LOGGER_MODULE_NAMES,
LOG_LEVELS_STR,
USE_DB_TRANSPORT,
configureCustomDBTransport,
getCustomLoggerForModule
} from '../../utils/logging/Logger.js'
Expand Down Expand Up @@ -62,13 +61,9 @@ describe('LogDatabase CRUD', () => {
message: `NEW Test log message ${Date.now()}`
}
// Trigger a log event which should be saved in the database
console.log('Will save log: ', newLogEntry)
console.log('has db transport?', logger.hasDBTransport())
logger.log(newLogEntry.level, newLogEntry.message)
console.log('USE_DB_TRANSPORT? ', USE_DB_TRANSPORT)
console.log('And now has db transport?', logger.hasDBTransport())
// Wait for the log to be written to the database
await new Promise((resolve) => setTimeout(resolve, 2000)) // Delay to allow log to be processed
await new Promise((resolve) => setTimeout(resolve, 1000)) // Delay to allow log to be processed

// Define the time frame for the log retrieval
const startTime = new Date(Date.now() - 10000) // 10 seconds ago
Expand Down
6 changes: 5 additions & 1 deletion src/utils/logging/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ function isTypesenseIgnoreLogMessage(loggerModuleName: string, logMessage: strin
const msg1: string = 'Response Code was 200.'
const msg2: string = 'Response Code was 201.'
const msg3 = 'request Try #1 to Node'
const msg4 = 'Request /collections/'
return (
loggerModuleName.toLowerCase() === LOGGER_MODULE_NAMES.DATABASE &&
(logMessage.includes(msg2) || logMessage.includes(msg3) || logMessage.includes(msg1))
(logMessage.includes(msg2) ||
logMessage.includes(msg3) ||
logMessage.includes(msg1) ||
logMessage.includes(msg4))
)
}

Expand Down

0 comments on commit 0437247

Please sign in to comment.