import LifecycleUnit from '../lifecycle/Unit.ts' import { Unit } from '../lifecycle/decorators.ts' import { Logging } from '../service/logging/Logging.ts' import StandardLogger from '../service/logging/StandardLogger.ts' import { isLoggingLevel } from '../service/logging/types.ts' import Utility from '../service/utility/Utility.ts' import { make } from '../../../di/src/global.ts' import 'https://deno.land/x/dotenv/load.ts' import { Container } from '../../../di/src/Container.ts' import { Inject } from '../../../di/src/decorator/Injection.ts' import CacheFactory from "../support/CacheFactory.ts"; const env = (name: string, fallback: any) => { const scaffolding = make(Scaffolding) return scaffolding.env(name) ?? fallback } export { env } @Unit() export default class Scaffolding extends LifecycleUnit { constructor( protected logger: Logging, protected utility: Utility, @Inject('injector') protected injector: Container, ) { super() } public env(name: string) { return this.utility.infer(Deno.env.get(name) ?? '') } public async up() { this.setup_logging() } public setup_logging() { StandardLogger.register() try { this.logger.verbose('Attempting to load logging level from the environment') const env_level = this.env('DATON_LOGGING_LEVEL') this.logger.verbose(`Read logging level: ${env_level}`) if ( isLoggingLevel(env_level) ) { this.logger.verbose('Logging level is valid.') this.logger.level = env_level this.logger.debug(`Set logging level from environment: ${env_level}`) } } catch (e) {} this.logger.info('Logging initialized.', true) this.logger.verbose('Adding the cache production factory to the container...') this.injector.register_factory(new CacheFactory()) } }