Skip to content

Commit

Permalink
feat(functions): set up some logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jlucktay committed Feb 6, 2024
1 parent 2f48820 commit b10fee9
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 9 deletions.
1 change: 1 addition & 0 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/logging": "^11.0.0",
"firebase-admin": "^11.11.1",
"firebase-functions": "^4.6.0"
},
Expand Down
17 changes: 17 additions & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { runWith } from "firebase-functions";
import { Logging } from "@google-cloud/logging";

// Start writing Firebase Functions
// https://firebase.google.com/docs/functions/typescript
Expand All @@ -7,6 +8,16 @@ const goVCSBase = "https://github.com/jlucktay";

export const goPackage = runWith({ memory: "128MB" }).https.onRequest(
(request, response) => {
const logging = new Logging();
const log = logging.log("goPackage");

const METADATA = {
resource: {
type: "cloud_function",
labels: { function_name: "goPackage" },
},
};

const firstSlash = request.path.substring(1).indexOf("/");
let basePackage = request.path;

Expand All @@ -25,6 +36,9 @@ export const goPackage = runWith({ memory: "128MB" }).https.onRequest(
const goImportMeta =
`<meta name="go-import" content="` + goImport.join(" ") + `">`;

const logGoImportMeta = { message: goImportMeta };
log.write(log.entry(METADATA, logGoImportMeta));

// https://github.com/golang/gddo/wiki/Source-Code-Links
// <meta name="go-source" content="prefix home directory file">
const goSource: string[] = [
Expand All @@ -37,6 +51,9 @@ export const goPackage = runWith({ memory: "128MB" }).https.onRequest(
const goSourceMeta =
`<meta name="go-source" content="` + goSource.join(" ") + `">`;

const logGoSourceMeta = { message: goSourceMeta };
log.write(log.entry(METADATA, logGoSourceMeta));

response.send(goImportMeta + "\n" + goSourceMeta + "\n");
},
);
Loading

0 comments on commit b10fee9

Please sign in to comment.