@@ -34,6 +34,7 @@ import AdminForthRestAPI, { interpretResource } from './modules/restApi.js';
3434import ClickhouseConnector from './dataConnectors/clickhouse.js' ;
3535import OperationalResource from './modules/operationalResource.js' ;
3636import SocketBroker from './modules/socketBroker.js' ;
37+ import { afLogger } from './modules/logger.js' ;
3738
3839// exports
3940export * from './types/Back.js' ;
@@ -124,62 +125,62 @@ class AdminForth implements IAdminForth {
124125 }
125126
126127 constructor ( config : AdminForthInputConfig ) {
127- process . env . HEAVY_DEBUG && console . log ( '🔧 AdminForth constructor started' ) ;
128+ afLogger . trace ( '🔧 AdminForth constructor started' ) ;
128129
129130 if ( global . adminforth ) {
130131 throw new Error ( 'AdminForth instance already created in this process. ' +
131132 'If you want to use multiple instances, consider using different process for each instance' ) ;
132133 }
133134
134- process . env . HEAVY_DEBUG && console . log ( '🔧 Creating CodeInjector...' ) ;
135+ afLogger . trace ( '🔧 Creating CodeInjector...' ) ;
135136 this . codeInjector = new CodeInjector ( this ) ;
136- process . env . HEAVY_DEBUG && console . log ( '🔧 CodeInjector created' ) ;
137+ afLogger . trace ( '🔧 CodeInjector created' ) ;
137138
138- process . env . HEAVY_DEBUG && console . log ( '🔧 Creating ConfigValidator...' ) ;
139+ afLogger . trace ( '🔧 Creating ConfigValidator...' ) ;
139140 this . configValidator = new ConfigValidator ( this , config ) ;
140- process . env . HEAVY_DEBUG && console . log ( '🔧 ConfigValidator created' ) ;
141+ afLogger . trace ( '🔧 ConfigValidator created' ) ;
141142
142- process . env . HEAVY_DEBUG && console . log ( '🔧 Creating AdminForthRestAPI...' ) ;
143+ afLogger . trace ( '🔧 Creating AdminForthRestAPI...' ) ;
143144 this . restApi = new AdminForthRestAPI ( this ) ;
144- process . env . HEAVY_DEBUG && console . log ( '🔧 AdminForthRestAPI created' ) ;
145+ afLogger . trace ( '🔧 AdminForthRestAPI created' ) ;
145146
146- process . env . HEAVY_DEBUG && console . log ( '🔧 Creating SocketBroker...' ) ;
147+ afLogger . trace ( '🔧 Creating SocketBroker...' ) ;
147148 this . websocket = new SocketBroker ( this ) ;
148- process . env . HEAVY_DEBUG && console . log ( '🔧 SocketBroker created' ) ;
149+ afLogger . trace ( '🔧 SocketBroker created' ) ;
149150
150151 this . activatedPlugins = [ ] ;
151152
152- process . env . HEAVY_DEBUG && console . log ( '🔧 Validating config...' ) ;
153+ afLogger . trace ( '🔧 Validating config...' ) ;
153154 this . configValidator . validateConfig ( ) ;
154- process . env . HEAVY_DEBUG && console . log ( '🔧 Config validated' ) ;
155+ afLogger . trace ( '🔧 Config validated' ) ;
155156
156- process . env . HEAVY_DEBUG && console . log ( '🔧 Activating plugins...' ) ;
157+ afLogger . trace ( '🔧 Activating plugins...' ) ;
157158 this . activatePlugins ( ) ;
158- process . env . HEAVY_DEBUG && console . log ( '🔧 Plugins activated' ) ;
159+ afLogger . trace ( '🔧 Plugins activated' ) ;
159160
160- process . env . HEAVY_DEBUG && console . log ( '🔧 Validating after plugin activation...' ) ;
161+ afLogger . trace ( '🔧 Validating after plugin activation...' ) ;
161162 this . configValidator . validateAfterPluginsActivation ( ) ;
162- process . env . HEAVY_DEBUG && console . log ( '🔧 Config validated' ) ;
163+ afLogger . trace ( '🔧 Config validated' ) ;
163164
164- process . env . HEAVY_DEBUG && console . log ( '🔧 Creating ExpressServer...' ) ;
165+ afLogger . trace ( '🔧 Creating ExpressServer...' ) ;
165166 this . express = new ExpressServer ( this ) ;
166- process . env . HEAVY_DEBUG && console . log ( '🔧 ExpressServer created' ) ;
167+ afLogger . trace ( '🔧 ExpressServer created' ) ;
167168
168169 // this.fastify = new FastifyServer(this);
169- process . env . HEAVY_DEBUG && console . log ( '🔧 Creating AdminForthAuth...' ) ;
170+ afLogger . trace ( '🔧 Creating AdminForthAuth...' ) ;
170171 this . auth = new AdminForthAuth ( this ) ;
171- process . env . HEAVY_DEBUG && console . log ( '🔧 AdminForthAuth created' ) ;
172+ afLogger . trace ( '🔧 AdminForthAuth created' ) ;
172173
173174 this . connectors = { } ;
174175 this . statuses = {
175176 dbDiscover : 'running' ,
176177 } ;
177178
178179 console . log ( `${ this . formatAdminForth ( ) } v${ ADMINFORTH_VERSION } initializing...` ) ;
179- process . env . HEAVY_DEBUG && console . log ( '🔧 About to set global.adminforth...' ) ;
180+ afLogger . trace ( '🔧 About to set global.adminforth...' ) ;
180181 global . adminforth = this ;
181- process . env . HEAVY_DEBUG && console . log ( '🔧 global.adminforth set successfully' ) ;
182- process . env . HEAVY_DEBUG && console . log ( '🔧 AdminForth constructor completed' ) ;
182+ afLogger . trace ( '🔧 global.adminforth set successfully' ) ;
183+ afLogger . trace ( '🔧 AdminForth constructor completed' ) ;
183184 }
184185
185186 formatAdminForth ( ) {
@@ -202,25 +203,25 @@ class AdminForth implements IAdminForth {
202203 }
203204
204205 activatePlugins ( ) {
205- process . env . HEAVY_DEBUG && console . log ( '🔌🔌🔌 Activating plugins' ) ;
206+ afLogger . trace ( '🔌🔌🔌 Activating plugins' ) ;
206207 const allPluginInstances = [ ] ;
207208 for ( let resource of this . config . resources ) {
208- process . env . HEAVY_DEBUG && console . log ( `🔌 Checking plugins for resource: ${ resource . resourceId } ` ) ;
209+ afLogger . trace ( `🔌 Checking plugins for resource: ${ resource . resourceId } ` ) ;
209210 for ( let pluginInstance of resource . plugins || [ ] ) {
210- process . env . HEAVY_DEBUG && console . log ( `🔌 Found plugin: ${ pluginInstance . constructor . name } for resource ${ resource . resourceId } ` ) ;
211+ afLogger . trace ( `🔌 Found plugin: ${ pluginInstance . constructor . name } for resource ${ resource . resourceId } ` ) ;
211212 allPluginInstances . push ( { pi : pluginInstance , resource} ) ;
212213 }
213214 }
214- process . env . HEAVY_DEBUG && console . log ( `🔌 Total plugins to activate: ${ allPluginInstances . length } ` ) ;
215+ afLogger . trace ( `🔌 Total plugins to activate: ${ allPluginInstances . length } ` ) ;
215216
216217 let activationLoopCounter = 0 ;
217218 while ( true ) {
218219 activationLoopCounter ++ ;
219220 if ( activationLoopCounter > 10 ) {
220221 throw new Error ( 'Plugin activation loop exceeded 10 iterations, possible infinite loop (some plugin tries to activate himself in a loop)' ) ;
221222 }
222- process . env . HEAVY_DEBUG && console . log ( `🔌 Plugin activation loop iteration: ${ activationLoopCounter } ` ) ;
223- process . env . HEAVY_DEBUG && console . log ( `🔌 Activated plugins count: ${ this . activatedPlugins . length } /${ allPluginInstances . length } ` ) ;
223+ afLogger . trace ( `🔌 Plugin activation loop iteration: ${ activationLoopCounter } ` ) ;
224+ afLogger . trace ( `🔌 Activated plugins count: ${ this . activatedPlugins . length } /${ allPluginInstances . length } ` ) ;
224225 const allPluginsAreActivated = allPluginInstances . length === this . activatedPlugins . length ;
225226 if ( allPluginsAreActivated ) {
226227 break ;
@@ -230,33 +231,33 @@ class AdminForth implements IAdminForth {
230231 ! this . activatedPlugins . find ( ( p ) => p . pluginInstanceId === pluginInstance . pluginInstanceId )
231232 ) ;
232233
233- process . env . HEAVY_DEBUG && console . log ( `🔌 Unactivated plugins remaining: ${ unactivatedPlugins . length } ` ) ;
234+ afLogger . trace ( `🔌 Unactivated plugins remaining: ${ unactivatedPlugins . length } ` ) ;
234235
235- process . env . HEAVY_DEBUG && console . log ( `🔌 Unactivated plugins count: ${ unactivatedPlugins . length } ` ) ;
236+ afLogger . trace ( `🔌 Unactivated plugins count: ${ unactivatedPlugins . length } ` ) ;
236237
237238 unactivatedPlugins . sort ( ( { pi : a } , { pi : b } ) => a . activationOrder - b . activationOrder ) ;
238- process . env . HEAVY_DEBUG && console . log ( `🔌 Activating plugins in order:` , unactivatedPlugins . map ( ( { pi} ) => pi . constructor . name ) ) ;
239+ afLogger . trace ( `🔌 Activating plugins in order: ${ unactivatedPlugins . map ( ( { pi} ) => pi . constructor . name ) } ` ) ;
239240 unactivatedPlugins . forEach (
240241 ( { pi : pluginInstance , resource} , index ) => {
241- process . env . HEAVY_DEBUG && console . log ( " Activating plugin:" , pluginInstance . constructor . name )
242- process . env . HEAVY_DEBUG && console . log ( `🔌 Activating plugin ${ index + 1 } /${ allPluginInstances . length } : ${ pluginInstance . constructor . name } for resource ${ resource . resourceId } ` ) ;
242+ afLogger . trace ( ` Activating plugin: ${ pluginInstance . constructor . name } ` ) ;
243+ afLogger . trace ( `🔌 Activating plugin ${ index + 1 } /${ allPluginInstances . length } : ${ pluginInstance . constructor . name } for resource ${ resource . resourceId } ` ) ;
243244 pluginInstance . modifyResourceConfig ( this , resource , allPluginInstances ) ;
244- process . env . HEAVY_DEBUG && console . log ( `🔌 Plugin ${ pluginInstance . constructor . name } modifyResourceConfig completed` ) ;
245+ afLogger . trace ( `🔌 Plugin ${ pluginInstance . constructor . name } modifyResourceConfig completed` ) ;
245246
246247 const plugin = this . activatedPlugins . find ( ( p ) => p . pluginInstanceId === pluginInstance . pluginInstanceId ) ;
247248 if ( plugin ) {
248- process . env . HEAVY_DEBUG && console . log ( `Current plugin pluginInstance.pluginInstanceId ${ pluginInstance . pluginInstanceId } ` ) ;
249+ afLogger . trace ( `Current plugin pluginInstance.pluginInstanceId ${ pluginInstance . pluginInstanceId } ` ) ;
249250
250251 throw new Error ( `Attempt to activate Plugin ${ pluginInstance . constructor . name } second time for same resource, but plugin does not support it.
251252 To support multiple plugin instance pre one resource, plugin should return unique string values for each installation from instanceUniqueRepresentation` ) ;
252253 }
253254 this . activatedPlugins . push ( pluginInstance ) ;
254- process . env . HEAVY_DEBUG && console . log ( `🔌 Plugin ${ pluginInstance . constructor . name } activated successfully` ) ;
255+ afLogger . trace ( `🔌 Plugin ${ pluginInstance . constructor . name } activated successfully` ) ;
255256 }
256257 ) ;
257- process . env . HEAVY_DEBUG && console . log ( `🔌activated plugins:` , this . activatedPlugins . map ( ( pi ) => pi . constructor . name ) ) ;
258+ afLogger . trace ( `🔌activated plugins: ${ this . activatedPlugins . map ( ( pi ) => pi . constructor . name ) } ` ) ;
258259 }
259- process . env . HEAVY_DEBUG && console . log ( '🔌 All plugins activation completed' ) ;
260+ afLogger . trace ( '🔌 All plugins activation completed' ) ;
260261 }
261262
262263 getPluginsByClassName < T > ( className : string ) : T [ ] {
@@ -584,7 +585,7 @@ class AdminForth implements IAdminForth {
584585 }
585586 }
586587 const connector = this . connectors [ resource . dataSource ] ;
587- process . env . HEAVY_DEBUG && console . log ( ' 🪲🆕 creating record createResourceRecord' , record ) ;
588+ afLogger . trace ( ` 🪲🆕 creating record createResourceRecord, record: ${ JSON . stringify ( record ) } ` ) ;
588589 const { error, createdRecord } = await connector . createRecord ( { resource, record, adminUser } ) ;
589590 if ( error ) {
590591 return { error } ;
@@ -594,7 +595,7 @@ class AdminForth implements IAdminForth {
594595
595596 // execute hook if needed
596597 for ( const hook of listify ( resource . hooks ?. create ?. afterSave ) ) {
597- process . env . HEAVY_DEBUG && console . log ( ' 🪲 Hook afterSave' , hook ) ;
598+ afLogger . trace ( ` 🪲 Hook afterSave ${ hook } ` ) ;
598599 const resp = await hook ( {
599600 recordId : primaryKey ,
600601 resource,
0 commit comments