You can specify debug strings when you run an application, as explained below, to display specific log output to the console. You can also redirect the output to a file, if desired. These techniques are often helpful in debugging applications.
Using debug strings
LoopBack has a number of built-in debug strings to help with debugging. Specify a string on the command-line via an environment variable as follows:
MacOS and Linux
$ DEBUG=<pattern>[,<pattern>...] npm start
Windows
C:\> set DEBUG=<pattern>[,<pattern>...]
C:\> npm start
where <pattern> is a string-matching pattern specifying debug strings to match. You can specify as many matching patterns as you wish.
For example (MacOS and Linux):
$ DEBUG=loopback:datasource npm start
Or, on Windows:
C:\> set DEBUG=loopback:datasource
C:\> npm start
You’ll see output such as (truncated for brevity):
loopback:datasource Settings: {"name":"db","debug":true} -0ms
loopback:datasource Settings: {"name":"geo","connector":"rest",...
You can use an asterisk (*) in the pattern to match any string. For example
the following would match any debug string containing “oracle”:
$ DEBUG=*oracle npm start
You can also exclude specific debuggers by prefixing them with a “-“ character.
For example, DEBUG=*,-rest-crud:* would include all debuggers except those
starting with “rest-crud:”.
Debug string format
These strings have the format
module[:area]:string
Where:
- module is the name of the module, for example
loopbackorloopback-connector-mongodb. - area is an optional identifier such as
cliorrepositoryto identify the purpose of the module - string is the debug string specified in the target TypeScript/JavaScript
source file, such as
application.ts.
For example:
loopback:cli:model-generator
The debug string model-generator is specified in the source file
generators/model/index.js
of the @loopback/cli module.
Debug strings reference
| Module | Source file | String |
|---|---|---|
| @loopback | ||
| @loopback/authorization | src/authorize-interceptor.ts | loopback:authorization:interceptor |
| @loopback/boot | src/bootstrapper.ts | loopback:boot:bootstrapper |
| src/booters/interceptor.booter.ts | loopback:boot:interceptor-booter | |
| src/booters/lifecycle-observer.booter.ts | loopback:boot:lifecycle-observer-booter | |
| src/booters/model-api.booter.ts | loopback:boot:model-api | |
| src/booters/service.booter.ts | loopback:boot:service-booter | |
| @loopback/booter-lb3app | src/lb3app.booter.ts | loopback:boot:lb3app |
| @loopback/cron | src/cron.component.ts | loopback:cron |
| @loopback/rest-crud | src/crud-rest-builder.ts | loopback:boot:crud-rest |
| @loopback/cli | please check each generator | loopback:cli:_string_ |
| @loopback/context | src/interceptor.ts | loopback:context:interceptor |
| src/binding.ts | loopback:context:binding | |
| src/context-view.ts | loopback:context:view | |
| src/invocation.ts | loopback:context:invocation | |
| src/interceptor-chain.ts | loopback:context:interceptor-chain | |
| @loopback/http-caching-proxy | src/http-caching-proxy.ts | loopback:http-caching-proxy |
| @loopback/core | src/lifecycle-registry.ts | loopback:core:lifecycle |
| src/application.ts | loopback:core:application | |
| @loopback/openapi-v3 | src/* | loopback:openapi |
| @loopback/repository | src/relations/belongs-to/belongs-to.accessor.ts | loopback:repository:relations:belongs-to:accessor |
| src/relations/belongs-to/belongs-to.accessor.ts | loopback:repository:relations:belongs-to:accessor | |
| src/relations/belongs-to/belongs-to.helpers.ts | loopback:repository:relations:belongs-to:helpers | |
| src/relations/has-many/has-many.helpers.ts | loopback:repository:relations:has-many:helpers | |
| src/relations/has-many/has-many.inclusion-resolver.ts | loopback:repository:relations:has-many:inclusion-resolver | |
| src/relations/has-many/has-many.repository-factory.ts | loopback:repository:relations:has-many:repository-factory | |
| src/relations/has-many/has-many-through.helpers.ts | loopback:repository:relations:has-many-through:helpers | |
| src/relations/has-many/has-many-through.inclusion-resolver.ts | loopback:repository:relations:has-many-through:inclusion-resolver | |
| src/relations/has-one/has-one.helpers.ts | loopback:repository:relations:has-one:helpers | |
| src/relations/has-one/has-one.repository-factory.ts | loopback:repository:relations:has-one:repository-factory | |
| @loopback/repository-json-schema | src/build-schema.ts | loopback:repository-json-schema:build-schema |
| @loopback/rest | src/rest-server/ | loopback:rest:server |
| src/sequence.ts | loopback:rest:sequence | |
| loopback-datasource-juggler | ||
| lib/datasource.js | loopback:datasource | |
| Connectors | ||
| loopback-connector | lib/connector.js | loopback:connector |
| loopback-connector-cassandra | lib/cassandra.js | loopback:connector:cassandra |
| loopback-connector-cloudant | lib/cloudant.js | loopback:connector:cloudant |
| loopback-connector-couchdb2 | lib/couchdb2.js | loopback:connector:couchdb2 |
| loopback-connector-dashdb | lib/dashdb.js | loopback:connector:dashdb |
| loopback-connector-db2 | lib/db2.js | loopback:connector:db2 |
| loopback-connector-ibmi | lib/ibmiconnector.js | loopback:connector:ibmiconnector |
| loopback-connector-kv-redis | lib/kv-redis.js | loopback:connector:kv-redis |
| loopback-connector-mongodb | lib/mongodb.js | loopback:connector:mongodb |
| loopback-connector-mssql | lib/mssql.js | loopback:connector:mssql |
| loopback-connector-mysql | lib/mysql.js | loopback:connector:mysql |
| loopback-connector-oracle | lib/oracle.js | loopback:connector:oracle |
| loopback-connector-postgresql | lib/postgresql.js | loopback:connector:postgresql |
| loopback-connector-rest | lib/rest-builder.js | loopback:connector:rest |
| lib/rest-connector.js | loopback:connector:rest | |
| lib/rest-model.js | loopback:connector:rest | |
| lib/swagger-client.js | loopback:connector:rest:swagger | |
| loopback-connector-soap | lib/soap-connector.js | loopback:connector:soap |