diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fc68b7e0..1b5b02d4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - (#183) Add a `configuration` attribute in the `mesg.yml` file to accept docker configuration for your service - (#187) Stop all services when the MESG Core stops - (#190) Possibility to `test` or `deploy` a service from a git or GitHub url +- (#233) Add logs in the `service test` command with service logs by default and all dependencies logs with the `--full-logs` flag - (#235) Add `ListServices` and `GetService` APIs #### Removed diff --git a/cmd/service/logs.go b/cmd/service/logs.go index 7356648bd..984000347 100644 --- a/cmd/service/logs.go +++ b/cmd/service/logs.go @@ -26,15 +26,24 @@ func init() { } func logsHandler(cmd *cobra.Command, args []string) { + closeReaders := showLogs(args[0], cmd.Flag("dependency").Value.String()) + defer closeReaders() + <-utils.WaitForCancel() +} + +func showLogs(serviceID string, dependency string) func() { reply, err := cli.GetService(context.Background(), &core.GetServiceRequest{ - ServiceID: args[0], + ServiceID: serviceID, }) utils.HandleError(err) - readers, err := reply.Service.Logs(cmd.Flag("dependency").Value.String()) + readers, err := reply.Service.Logs(dependency) utils.HandleError(err) for _, reader := range readers { - defer reader.Close() go stdcopy.StdCopy(os.Stdout, os.Stderr, reader) } - <-utils.WaitForCancel() + return func() { + for _, reader := range readers { + reader.Close() + } + } } diff --git a/cmd/service/test.go b/cmd/service/test.go index 5c990aaa9..ae21fafbb 100644 --- a/cmd/service/test.go +++ b/cmd/service/test.go @@ -22,6 +22,7 @@ var Test = &cobra.Command{ See more detail on the [Test page from the documentation](https://docs.mesg.tech/service/test.html)`, Example: `mesg-core service test mesg-core service test ./SERVICE_FOLDER +mesg-core service test --logs-all mesg-core service test --event-filter EVENT_NAME mesg-core service test --task TASK_NAME --data ./PATH_TO_DATA_FILE.json mesg-core service test --task-filter TASK_NAME --output-filter OUTPUT_NAME @@ -38,6 +39,7 @@ func init() { Test.Flags().StringP("event-filter", "e", "*", "Only log the data of the given event") Test.Flags().StringP("task-filter", "r", "", "Only log the result of the given task") Test.Flags().StringP("output-filter", "o", "", "Only log the data of the given output of a task result. If set, you also need to set the task in --task-filter") + Test.Flags().BoolP("logs-all", "a", false, "Display logs from service and its dependencies") } func listenEvents(serviceID string, filter string) { @@ -96,7 +98,6 @@ func executeTask(serviceID string, task string, dataPath string) (execution *cor } func testHandler(cmd *cobra.Command, args []string) { - var err error serviceID := cmd.Flag("serviceID").Value.String() if serviceID == "" { service := prepareService(defaultPath(args)) @@ -119,6 +120,12 @@ func testHandler(cmd *cobra.Command, args []string) { go listenEvents(serviceID, cmd.Flag("event-filter").Value.String()) go listenResults(serviceID, cmd.Flag("task-filter").Value.String(), cmd.Flag("output-filter").Value.String()) + logs := "service" + if cmd.Flag("logs-all").Value.String() == "true" { + logs = "*" + } + closeReaders := showLogs(serviceID, logs) + defer closeReaders() time.Sleep(time.Second) executeTask(serviceID, cmd.Flag("task").Value.String(), cmd.Flag("data").Value.String()) @@ -126,11 +133,10 @@ func testHandler(cmd *cobra.Command, args []string) { if cmd.Flag("keep-alive").Value.String() != "true" { utils.ShowSpinnerForFunc(utils.SpinnerOptions{Text: "Stopping service..."}, func() { - _, err = cli.StopService(context.Background(), &core.StopServiceRequest{ + cli.StopService(context.Background(), &core.StopServiceRequest{ ServiceID: serviceID, }) }) - utils.HandleError(err) fmt.Println(aurora.Green("Service stopped")) } } diff --git a/docs/cli/mesg-core.md b/docs/cli/mesg-core.md index 0ebaa1bf0..b50775804 100644 --- a/docs/cli/mesg-core.md +++ b/docs/cli/mesg-core.md @@ -1,10 +1,10 @@ ## mesg-core -MESG CORE +MESG Core ### Synopsis -MESG CORE +MESG Core ### Options @@ -14,6 +14,9 @@ MESG CORE ### SEE ALSO -* [mesg-core daemon](mesg-core_daemon.md) - Manage the MESG daemon +* [mesg-core logs](mesg-core_logs.md) - Show the MESG Core's logs * [mesg-core service](mesg-core_service.md) - Manage your services +* [mesg-core start](mesg-core_start.md) - Start the MESG Core +* [mesg-core status](mesg-core_status.md) - Status of the MESG Core +* [mesg-core stop](mesg-core_stop.md) - Stop the MESG Core diff --git a/docs/cli/mesg-core_logs.md b/docs/cli/mesg-core_logs.md new file mode 100644 index 000000000..7c11164c4 --- /dev/null +++ b/docs/cli/mesg-core_logs.md @@ -0,0 +1,22 @@ +## mesg-core logs + +Show the MESG Core's logs + +### Synopsis + +Show the MESG Core's logs + +``` +mesg-core logs [flags] +``` + +### Options + +``` + -h, --help help for logs +``` + +### SEE ALSO + +* [mesg-core](mesg-core.md) - MESG Core + diff --git a/docs/cli/mesg-core_service.md b/docs/cli/mesg-core_service.md index 1066f049b..76fe4b043 100644 --- a/docs/cli/mesg-core_service.md +++ b/docs/cli/mesg-core_service.md @@ -14,12 +14,13 @@ Manage your services ### SEE ALSO -* [mesg-core](mesg-core.md) - MESG CORE -* [mesg-core service delete](mesg-core_service_delete.md) - Delete a service +* [mesg-core](mesg-core.md) - MESG Core +* [mesg-core service delete](mesg-core_service_delete.md) - Delete one or many services * [mesg-core service deploy](mesg-core_service_deploy.md) - Deploy a service * [mesg-core service detail](mesg-core_service_detail.md) - Show details of a published service * [mesg-core service init](mesg-core_service_init.md) - Initialize a service * [mesg-core service list](mesg-core_service_list.md) - List all published services +* [mesg-core service logs](mesg-core_service_logs.md) - Show the logs of a service * [mesg-core service start](mesg-core_service_start.md) - Start a service * [mesg-core service status](mesg-core_service_status.md) - List started services * [mesg-core service stop](mesg-core_service_stop.md) - Stop a service diff --git a/docs/cli/mesg-core_service_delete.md b/docs/cli/mesg-core_service_delete.md index 764305bfc..6494eda4f 100644 --- a/docs/cli/mesg-core_service_delete.md +++ b/docs/cli/mesg-core_service_delete.md @@ -1,10 +1,10 @@ ## mesg-core service delete -Delete a service +Delete one or many services ### Synopsis -Delete a service +Delete one or many services ``` mesg-core service delete [flags] @@ -13,12 +13,14 @@ mesg-core service delete [flags] ### Examples ``` -mesg-core service delete +mesg-core service delete SERVICE_ID +mesg-core service delete SERVICE_ID_1 SERVICE_ID_2 ``` ### Options ``` + --all Delete all services -h, --help help for delete ``` diff --git a/docs/cli/mesg-core_service_deploy.md b/docs/cli/mesg-core_service_deploy.md index fd2e00803..aa163d64f 100644 --- a/docs/cli/mesg-core_service_deploy.md +++ b/docs/cli/mesg-core_service_deploy.md @@ -4,9 +4,9 @@ Deploy a service ### Synopsis -Deploy a service on the Network. +Deploy a service. -To get more information, see the [deploy page from the documentation](https://docs.mesg.tech/service/publish-a-service) +To get more information, see the [deploy page from the documentation](https://docs.mesg.com/service/deploy-a-service) ``` mesg-core service deploy [flags] @@ -15,7 +15,7 @@ mesg-core service deploy [flags] ### Examples ``` -mesg-core sevice deploy +mesg-core service deploy PATH_TO_SERVICE ``` ### Options diff --git a/docs/cli/mesg-core_service_logs.md b/docs/cli/mesg-core_service_logs.md new file mode 100644 index 000000000..d5e26b2b4 --- /dev/null +++ b/docs/cli/mesg-core_service_logs.md @@ -0,0 +1,30 @@ +## mesg-core service logs + +Show the logs of a service + +### Synopsis + +Show the logs of a service + +``` +mesg-core service logs [flags] +``` + +### Examples + +``` +mesg-core service logs SERVICE_ID +mesg-core service logs SERVICE_ID --dependency DEPENDENCY_NAME +``` + +### Options + +``` + -d, --dependency string Name of the dependency to only show the logs from (default "*") + -h, --help help for logs +``` + +### SEE ALSO + +* [mesg-core service](mesg-core_service.md) - Manage your services + diff --git a/docs/cli/mesg-core_service_test.md b/docs/cli/mesg-core_service_test.md index ae50802a0..6492ab588 100644 --- a/docs/cli/mesg-core_service_test.md +++ b/docs/cli/mesg-core_service_test.md @@ -17,22 +17,24 @@ mesg-core service test [flags] ``` mesg-core service test mesg-core service test ./SERVICE_FOLDER -mesg-core service test --event EVENT_NAME -mesg-core service test --task TASK_NAME --data ./PATH_TO_DATA_FILE.yml -mesg-core service test --keep-alive +mesg-core service test --event-filter EVENT_NAME +mesg-core service test --task TASK_NAME --data ./PATH_TO_DATA_FILE.json +mesg-core service test --task-filter TASK_NAME --output-filter OUTPUT_NAME +mesg-core service test --serviceID SERVICE_ID --keep-alive ``` ### Options ``` - -d, --data string Path to the file containing the data required to run the task - -e, --event string Only log a specific event (default "*") - -h, --help help for test - --keep-alive Do not stop the service - -o, --output string Filter output of a task - -r, --result string Filter the result of a specific task - -s, --service string Debug a deployed service - -t, --task string Run a specific task + -d, --data string Path to the file containing the data required to run the task + -e, --event-filter string Only log the data of the given event (default "*") + -f, --full-logs Display logs from service and its dependencies + -h, --help help for test + --keep-alive Do not stop the service at the end of this command + -o, --output-filter string Only log the data of the given output of a task result. If set, you also need to set the task in --task-filter + -s, --serviceID string ID of a previously deployed service + -t, --task string Run the given task + -r, --task-filter string Only log the result of the given task ``` ### SEE ALSO diff --git a/docs/cli/mesg-core_start.md b/docs/cli/mesg-core_start.md new file mode 100644 index 000000000..5e86d6c9d --- /dev/null +++ b/docs/cli/mesg-core_start.md @@ -0,0 +1,22 @@ +## mesg-core start + +Start the MESG Core + +### Synopsis + +Start the MESG Core + +``` +mesg-core start [flags] +``` + +### Options + +``` + -h, --help help for start +``` + +### SEE ALSO + +* [mesg-core](mesg-core.md) - MESG Core + diff --git a/docs/cli/mesg-core_status.md b/docs/cli/mesg-core_status.md new file mode 100644 index 000000000..6f47cab0b --- /dev/null +++ b/docs/cli/mesg-core_status.md @@ -0,0 +1,22 @@ +## mesg-core status + +Status of the MESG Core + +### Synopsis + +Status of the MESG Core + +``` +mesg-core status [flags] +``` + +### Options + +``` + -h, --help help for status +``` + +### SEE ALSO + +* [mesg-core](mesg-core.md) - MESG Core + diff --git a/docs/cli/mesg-core_stop.md b/docs/cli/mesg-core_stop.md new file mode 100644 index 000000000..1e2b8ad65 --- /dev/null +++ b/docs/cli/mesg-core_stop.md @@ -0,0 +1,22 @@ +## mesg-core stop + +Stop the MESG Core + +### Synopsis + +Stop the MESG Core + +``` +mesg-core stop [flags] +``` + +### Options + +``` + -h, --help help for stop +``` + +### SEE ALSO + +* [mesg-core](mesg-core.md) - MESG Core +