-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: add running and debugging pages #5335
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
title: 'Running and debugging apps' | ||
lang: en | ||
keywords: LoopBack 4.0, LoopBack 4, Debug | ||
sidebar: lb4_sidebar | ||
permalink: /doc/en/lb4/Running-and-debugging-apps.html | ||
summary: | ||
--- | ||
|
||
In general, when you are developing an application, use the `npm` command to run | ||
it. This enables you to see stack traces and console output immediately. | ||
|
||
For example: | ||
|
||
``` | ||
$ cd myapp | ||
$ npm start | ||
``` | ||
|
||
LoopBack 4 also allows you to specify debug strings that the application will | ||
display to the console (or save to a file) to help you verify or diagnose the | ||
app. See [Setting debug strings](Setting-debug-strings.md). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,329 @@ | ||
--- | ||
title: 'Setting debug strings' | ||
lang: en | ||
keywords: LoopBack 4.0, LoopBack 4, base-connector.js | ||
sidebar: lb4_sidebar | ||
permalink: /doc/en/lb4/Setting-debug-strings.html | ||
summary: | ||
--- | ||
|
||
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** | ||
|
||
```shell | ||
$ DEBUG=<pattern>[,<pattern>...] npm start | ||
``` | ||
|
||
**Windows** | ||
|
||
```shell | ||
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): | ||
|
||
```shell | ||
$ DEBUG=loopback:datasource npm start | ||
``` | ||
|
||
Or, on Windows: | ||
|
||
```shell | ||
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": | ||
|
||
```shell | ||
$ 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 `loopback` or | ||
`loopback-connector-mongodb`. | ||
- _area_ is an optional identifier such as `cli` or `repository` to 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`](https://github.com/strongloop/loopback-next/blob/master/packages/cli/generators/model/index.js) | ||
of the `@loopback/cli` module. | ||
|
||
## Debug strings reference | ||
|
||
<table> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you create this table by hand? Can we automate this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if we have any script to do it, so I checked modules one by one 😳 And I didn't include all of the debug strings in here, or the list would be extremely long... I only include those important (from my understanding) ones. Any suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A shell script will do. Or monkey patch the debug function :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a script I just made: #!/bin/bash
clear
FILE_EXTENSION=$1
SEARCH_TEXT=$2
echo ""
echo " Files with extension : '${FILE_EXTENSION}' "
echo " that contains text : '${SEARCH_TEXT}' : "
echo "----------------------------------------------"
echo ""
find . -name "${FILE_EXTENSION}" -exec grep -h "${SEARCH_TEXT}" {} +
echo ""
echo ""
# include file name and found search text
# find . -name "*.ts" -exec grep "debugFactory('loopback" {} +
# only show found search text
# find . -name "*.ts" -exec grep -h "debugFactory('loopback" {} + Call ./find_files_with_text.sh "*.ts" "'loopback:" If you want to see : filename searchText in the results, remove the Based on my search string above, I found: Files with extension : '*.ts'
that contains text : ''loopback:' :
----------------------------------------------
const debug = require('debug')('loopback:benchmark');
const debug = debugFactory('loopback:cron');
const debug = debugFactory('loopback:multi-tenancy:strategy:query');
const debug = debugFactory('loopback:multi-tenancy:strategy:header');
const debug = debugFactory('loopback:multi-tenancy:strategy:host');
const debug = debugFactory('loopback:multi-tenancy:strategy:jwt');
const debug = debugFactory('loopback:multi-tenancy:action');
const debug = require('debug')('loopback:example:acl');
const debug = debugFactory('loopback:boot:lb3app');
const debug = debugFactory('loopback:repository:belongs-to-accessor');
const debug = debugFactory('loopback:repository:belongs-to-helpers');
const debug = debugFactory('loopback:repository:has-one-helpers');
const debug = debugFactory('loopback:repository:has-one-repository-factory');
const debug = debugFactory('loopback:repository:has-many-repository-factory');
const debug = debugFactory('loopback:repository:has-many-inclusion-resolver');
const debug = debugFactory('loopback:repository:has-many-helpers');
const debug = debugFactory('loopback:repository:relation-helpers');
export const RELATIONS_KEY = 'loopback:relations';
const debug = debugFactory('loopback:repository:mixin');
>('loopback:model');
>('loopback:model-properties');
>('loopback:model-and-properties');
const debug = debugFactory('loopback:context:binding');
const debug = debugFactory('loopback:context:invocation');
const debug = debugFactory('loopback:context:interceptor');
const debug = debugModule('loopback:context:resolver');
const debug = debugFactory('loopback:context:binding-inspector');
* const debug = debugFactory('loopback:context:application');
* return 'loopback:context:application';
if (this.constructor === Context) return 'loopback:context';
const debug = debugFactory('loopback:context:subscription');
expect(myCtx.debugFn.namespace).to.eql('loopback:context:mycontext');
const debug = debugModule('loopback:context:test');
const debug = debugFactory('loopback:context:interceptor-chain');
const debugSession = debugModule('loopback:context:resolver:session');
const debug = debugFactory('loopback:context:view');
const debug = debugFactory('loopback:core:lifecycle');
const debug = debugFactory('loopback:core:application');
const debugShutdown = debugFactory('loopback:core:application:shutdown');
const debugWarning = debugFactory('loopback:core:application:warning');
const debug = debugFactory('loopback:boot:booter-utils');
const debug = debugFactory('loopback:boot:base-artifact-booter');
const debug = debugFactory('loopback:boot:lifecycle-observer-booter');
const debug = debugFactory('loopback:boot:interceptor-booter');
const debug = debugFactory('loopback:boot:service-booter');
const debug = debugModule('loopback:boot:booter:application-metadata');
const debug = debugFactory('loopback:boot:model-api');
const debug = debugModule('loopback:boot:bootstrapper');
const debug = debugFactory('loopback:http-caching-proxy');
const debug = debugFactory('loopback:tsdocs');
const debug = debugFactory('loopback:tsdocs');
>('loopback:json-schema');
const debug = debugFactory('loopback:repository-json-schema:build-schema');
'loopback:openapi3:metadata:controller-spec:deprecated',
const debug = require('debug')('loopback:openapi3:metadata:requestbody');
const debug = debugModule('loopback:openapi:spec-enhancer');
const debug = debugModule('loopback:openapi:spec-enhancer');
const debug = debugModule('loopback:openapi:spec-enhancer');
const debug = require('debug')('loopback:openapi3:metadata:controller-spec');
const debug = debugFactory('loopback:repository-tests');
const debug = debugFactory('loopback:authorization:interceptor');
const debug = debugModule('loopback:metadata:decorator');
const debug = debugFactory('loopback:boot:crud-rest');
const debug = debugFactory('loopback:openapi:spec-enhancer:consolidate');
const debug = debugFactory('loopback:openapi:spec-enhancer:info');
const debug = debugModule('loopback:rest:body-parser');
const debug = debugModule('loopback:rest:body-parser');
const debug = debugFactory('loopback:rest:parser');
const debug = debugFactory('loopback:openapi:spec-enhancer');
const debug = require('debug')('loopback:rest:sequence');
const debug = debugFactory('loopback:rest:server');
const debug = debugModule('loopback:rest:coercion');
const debug = debugModule('loopback:rest:coercion');
const debug = debugModule('loopback:rest:ajv');
const debug = debugModule('loopback:rest:validation');
const debug = require('debug')('loopback:rest:router:trie');
const debug = debugFactory('loopback:rest:routing-table');
const debug = require('debug')('loopback:rest:router:regexp');
const debug = debugFactory('loopback:rest:controller-route');
but feel free to adjust the search string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks!! I also found that some packages have different ways to define the string e.g |
||
<tbody> | ||
<tr> | ||
<th width="240">Module</th> | ||
<th width="330">Source file</th> | ||
<th width="330">String</th> | ||
</tr> | ||
<tr> | ||
<th colspan="2">@loopback</th> | ||
</tr> | ||
<tr> | ||
<td>@loopback/authorization</td> | ||
<td>src/authorize-interceptor.ts</td> | ||
<td>loopback:authorization:interceptor</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/boot</td> | ||
<td>src/bootstrapper.ts</td> | ||
<td>loopback:boot:bootstrapper</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/booters/interceptor.booter.ts</td> | ||
<td>loopback:boot:interceptor-booter</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/booters/lifecycle-observer.booter.ts</td> | ||
<td>loopback:boot:lifecycle-observer-booter</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/booters/model-api.booter.ts</td> | ||
<td>loopback:boot:model-api</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/booters/service.booter.ts</td> | ||
<td>loopback:boot:service-booter</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/booter-lb3app</td> | ||
<td>src/lb3app.booter.ts</td> | ||
<td>loopback:boot:lb3app</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/cron</td> | ||
<td>src/cron.component.ts</td> | ||
<td>loopback:cron</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/rest-crud</td> | ||
<td>src/crud-rest-builder.ts</td> | ||
<td>loopback:boot:crud-rest</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/cli</td> | ||
<td>please check each generator</td> | ||
<td>loopback:cli:_string_</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/context</td> | ||
<td>src/interceptor.ts</td> | ||
<td>loopback:context:interceptor</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/binding.ts</td> | ||
<td>loopback:context:bindging</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/context-view.ts</td> | ||
<td>loopback:context:view</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/invocation.ts</td> | ||
<td>loopback:context:invocation</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/interceptor-chain.ts</td> | ||
<td>loopback:context:interceptor-chain</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/http-caching-proxy</td> | ||
<td>src/http-caching-proxy.ts</td> | ||
<td>loopback:http-caching-proxy</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/core</td> | ||
<td>src/lifecycle-registry.ts</td> | ||
<td>loopback:core:lifecycle</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/application.ts</td> | ||
<td>loopback:core:application</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/openapi-v3</td> | ||
<td>src/<sup>*</sup></td> | ||
<td>loopback:openapi</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/repository</td> | ||
<td>src/relations/belongs-to/belongs-to-accessor.ts</td> | ||
<td>loopback:repository:belongs-to-accessor</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/relations/has-many/has-many-repository-factory.ts</td> | ||
<td>loopback:repository:has-many-repository-factory</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/relations/has-one/has-one-repository-factory.ts</td> | ||
<td>loopback:repository:has-one-repository-factory</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/repository-json-schema</td> | ||
<td>src/build-schema.ts</td> | ||
<td>loopback:repository-json-schema:build-schema</td> | ||
</tr> | ||
<tr> | ||
<td>@loopback/rest</td> | ||
<td>src/rest-server/</td> | ||
<td>loopback:rest:server</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>src/sequence.ts</td> | ||
<td>loopback:rest:sequence</td> | ||
</tr> | ||
<tr> | ||
<th colspan="2"><span>loopback-datasource-juggler</span></th> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>lib/datasource.js</td> | ||
<td>loopback:datasource</td> | ||
</tr> | ||
<tr> | ||
<th colspan="2">Connectors</th> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector</td> | ||
<td>lib/connector.js</td> | ||
<td>loopback:connector</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-cassandra</td> | ||
<td>lib/cassandra.js</td> | ||
<td>loopback:connector:cassandra</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-cloudant</td> | ||
<td>lib/cloudant.js</td> | ||
<td>loopback:connector:cloudant</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-couchdb2</td> | ||
<td>lib/couchdb2.js</td> | ||
<td>loopback:connector:couchdb2</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-dashdb</td> | ||
<td>lib/dashdb.js</td> | ||
<td>loopback:connector:dashdb</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-db2</td> | ||
<td>lib/db2.js</td> | ||
<td>loopback:connector:db2</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-ibmi</td> | ||
<td>lib/ibmiconnector.js</td> | ||
<td>loopback:connector:ibmiconnector</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-kv-redis</td> | ||
<td>lib/kv-redis.js</td> | ||
<td>loopback:connector:kv-redis</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-mongodb</td> | ||
<td>lib/mongodb.js</td> | ||
<td>loopback:connector:mongodb</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-mssql</td> | ||
<td>lib/mssql.js</td> | ||
<td>loopback:connector:mssql</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-mysql</td> | ||
<td>lib/mysql.js</td> | ||
<td>loopback:connector:mysql</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-oracle</td> | ||
<td>lib/oracle.js</td> | ||
<td>loopback:connector:oracle</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-postgresql</td> | ||
<td>lib/postgresql.js</td> | ||
<td>loopback:connector:postgresql</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-rest</td> | ||
<td>lib/rest-builder.js</td> | ||
<td>loopback:connector:rest</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>lib/rest-connector.js</td> | ||
<td>loopback:connector:rest</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>lib/rest-model.js</td> | ||
<td>loopback:connector:rest</td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td>lib/swagger-client.js</td> | ||
<td>loopback:connector:rest:swagger</td> | ||
</tr> | ||
<tr> | ||
<td>loopback-connector-soap</td> | ||
<td>lib/soap-connector.js</td> | ||
<td>loopback:connector:soap</td> | ||
</tr> | ||
</tbody> | ||
</table> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, will fix it in #4846