Skip to content

Commit

Permalink
[cb-#99] finish logging using deno_std log
Browse files Browse the repository at this point in the history
  • Loading branch information
crookse committed Dec 27, 2019
1 parent af61c35 commit 374b7cc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 48 deletions.
@@ -1,18 +1,9 @@
import Drash from "https://deno.land/x/drash/mod.ts";
import * as log from "https://deno.land/std/log/mod.ts";

export default class HomeResource extends Drash.Http.Resource {
static paths = ["/"];

public GET() {
log.info("Setting a response.");
this.response.body = "Hello!";
return this.response;
}
}
import HomeResource from "./home_resource.ts";

let server = new Drash.Http.Server({
address: "localhost:1337",
address: "localhost:1447",
response_output: "application/json",
resources: [HomeResource]
});
Expand Down
@@ -0,0 +1,15 @@
import Drash from "https://deno.land/x/drash/mod.ts";
import * as log from "https://deno.land/std/log/mod.ts";

export default class HomeResource extends Drash.Http.Resource {

static paths = ["/"];

public GET() {
log.info("Setting a response.");

this.response.body = "Hello!";

return this.response;
}
}

This file was deleted.

@@ -1,39 +1,3 @@
<template lang="pug">
page-tutorial-default
div.row
div.col
hr
h2#before-you-get-started Before You Get Started
ul
li <a href="https://github.com/denoland/deno_std" target="_BLANK">deno_std</a> has a <a href="https://github.com/denoland/deno_std/tree/master/log" target="_BLANK">Log</a> module that is readily available and you can use it as your logger of choice.
li Drash uses deno_std v{{ $conf.deno_std_version }}.
list-item-download-source-code(:source_code_uri="$route.meta.source_code_uri")
div.row
div.col
hr
h2#steps Steps
ol
li Create your app file.
code-block(:data="example_code.app")
div.row
div.col
hr
ul
li Run your app.
code-block(:data="example_code.run")
li Enter the following URL in your browser:
code-block-slotted(:header="false")
template(#code)
| localhost:1337
li Check the terminal you started your app with and you should see the following output:
code-block-slotted
template(#title) Terminal
template(#code)
| Deno server started at localhost:1337.
|
| INFO Setting a response.
</template>

<script>
export const resource = {
paths: ["/tutorials/logging/logging-using-log-from-deno-std"],
Expand All @@ -50,10 +14,62 @@ export default {
toc: {
items: [
"Before You Get Started",
"Folder Structure End State",
"Steps",
"Verification",
]
}
};
},
}
</script>

<template lang="pug">
page-tutorial(
:toc="toc"
)
div.row
div.col
hr
h2-hash Before You Get Started
p <a href="https://github.com/denoland/deno_std" target="_BLANK">deno_std</a> has a <a href="https://github.com/denoland/deno_std/tree/master/log" target="_BLANK">Log</a> module that is readily available and you can use it as your logger of choice.
p Drash uses deno_std v{{ $conf.deno_std_version }}.
p-download-source-code(:source_code_uri="$route.meta.source_code_uri")
div.row
div.col
hr
h2-hash Steps
ol
li Create your resource file.
code-block(:data="example_code.home_resource")
p Your resource file will load in the log module and use it to write a log message before setting the response's body.
li Create your app file.
code-block(:data="example_code.app")
div.row
div.col
hr
h2-hash Verification
ol
li Run your app.
p
code-block-slotted
template(v-slot:title) Terminal
template(v-slot:code)
| deno --allow-net app.ts
li Make a request using <code>curl</code> like below or go to <code>localhost:1447/</code> in your browser.
p
code-block-slotted
template(v-slot:title) Terminal
template(v-slot:code)
| curl localhost:1447/
p You should receive the following response:
p
code-block-slotted(language="javascript" :header="false")
template(v-slot:code)
| "Hello!"
li Check the terminal you used to start <code>app.ts</code>. The log message in <code>HomeResource</code> will be displayed.
code-block-slotted
template(v-slot:title) Terminal
template(v-slot:code)
| INFO Setting a response.
</template>

0 comments on commit 374b7cc

Please sign in to comment.