Skip to content

Commit

Permalink
updates of constants, plus docs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ocean committed Jul 15, 2024
1 parent 406cf32 commit f109cdd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
3 changes: 3 additions & 0 deletions env.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Environmental variables are also tracked in `ENVIRONMENT_VARIABLES` within `src/
- `MAX_REQ_PER_SECOND`: Number of requests per second allowed by the same client. Example: `3`
- `MAX_CHECKSUM_LENGTH`: Define the maximum length for a file if checksum is required (Mb). Example: `10`
- `LOG_LEVEL`: Define the default log level. Example: `debug`
- `LOG_CONSOLE`: Write logs to the console. Default is `false`
- `LOG_FILES`: Write logs to files. Default is `false`
- `LOG_DB`: Write logs to noSQL database. Default is `true`

## HTTP

Expand Down
3 changes: 1 addition & 2 deletions src/components/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,11 +1014,10 @@ export class Database {
// once we create a DB instance, the logger will be using this transport as well
// we cannot have this the other way around because of the dependencies cycle
if (USE_DB_TRANSPORT) {
console.log('DB USE_DB_TRANSPORT ', USE_DB_TRANSPORT)
configureCustomDBTransport(this, DATABASE_LOGGER)
} else {
DATABASE_LOGGER.warn(
'"NODE_ENV" is set to "development". This means logs will be saved to console and file(s) only.'
'Property "LOG_DB" is set to "false". This means logs will NOT be saved to database!'
)
}
return (async (): Promise<Database> => {
Expand Down
5 changes: 1 addition & 4 deletions src/test/integration/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('LogDatabase CRUD', () => {
'meta'
)
logId = result?.id // Save the auto-generated id for further operations
console.log('log id: ' + logId)
})

it('retrieve log', async () => {
Expand Down Expand Up @@ -72,14 +71,12 @@ describe('LogDatabase CRUD', () => {

// Retrieve the latest log entry
const logs = await database.logs.retrieveMultipleLogs(startTime, endTime, 1)
console.log('logs are: ', logs)

expect(logs?.length).to.equal(1)
expect(logs?.[0].id).to.equal(String(Number(logId) + 1))
expect(logs?.[0].id).to.greaterThan(Number(logId))
expect(logs?.[0].level).to.equal(newLogEntry.level)
expect(logs?.[0].message).to.equal(newLogEntry.message)
expect(logs?.[0].moduleName).to.equal('HTTP')
console.log('end debug')
})

it('should save a log in the database when a log.logMessage is called', async () => {
Expand Down
18 changes: 18 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,24 @@ export const ENVIRONMENT_VARIABLES: Record<any, EnvVariable> = {
name: 'LOG_LEVEL',
value: process.env.LOG_LEVEL,
required: false
},
LOG_CONSOLE: {
// log to console output?
name: 'LOG_CONSOLE',
value: process.env.LOG_CONSOLE,
required: false
},
LOG_FILES: {
// log to files?
name: 'LOG_FILES',
value: process.env.LOG_FILES,
required: false
},
LOG_DB: {
// log to DB?
name: 'LOG_DB',
value: process.env.LOG_DB,
required: false // default is true
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/utils/logging/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ const USE_CONSOLE_TRANSPORT: boolean =
process.env.LOG_CONSOLE && process.env.LOG_CONSOLE !== 'false'
const USE_FILE_TRANSPORT: boolean =
process.env.LOG_FILES && process.env.LOG_FILES !== 'false'
// can be affected by configuration
export const USE_DB_TRANSPORT: boolean =
true || (process.env.LOG_DB && process.env.LOG_DB !== 'false')
// default to true, if not explicitly set otherwise
export const USE_DB_TRANSPORT: boolean = !(
process.env.LOG_DB && process.env.LOG_DB === 'false'
)

// if not set, then gets default 'development' level & colors
export function isDevelopmentEnvironment(): boolean {
Expand Down

0 comments on commit f109cdd

Please sign in to comment.