question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AzFunc 'context' object

See original GitHub issue

Hi Yves

I haven’t find any sample that show a usage of the Azure Functions “context” object. This one is passed through the function as arg when you create a new HTTP Trigger Function : module.exports = function (context, req) and allow you to .log() information, very useful.

Could you tell me how could I get this object within the context of using your library please ? Many thanks 😃

Kind Regards

Olivier

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mderazoncommented, Feb 7, 2018

FWIW this seems to have worked:

const { Writable } = require('stream');

app.use((req, res, next) => {
  const myStream = new Writable({
    write(chunk, encoding, callback) {
      req.context.log(chunk.toString());
      callback();
    }
  });
  morgan('combined', { stream: myStream })(req, res, next);
});
0reactions
mderazoncommented, Feb 7, 2018

any idea how to make it work with logger like morgan ?

Tried something like this:


const { Writable } = require('stream');

app.use((req, res, next) => {
  process.stdout = new Writable({
    write(chunk, encoding, callback) {
      req.context.log(chunk.toString());
      callback();
    }
  });
  next();
});

app.use(morgan('combined'));

but didn’t work

Read more comments on GitHub >

github_iconTop Results From Across the Web

Example context object for Azure Functions · GitHub
Example context object for Azure Functions. GitHub Gist: instantly share code, notes, and snippets.
Read more >
Context Class - azure-functions - Microsoft Learn
Context of the durable orchestration execution. Parameter data for orchestration bindings that can be used to schedule function-based activities.
Read more >
How inject 2 db context to .Net Azure Functions?
Net Azure Functions solution, i injected one entity DbContext and worked fine, but how do i inject another context on Startup.cs?
Read more >
PoshServerLess.psm1 0.1.2 - PowerShell Gallery
GetFile -CloudFilesObject $StorageFileObject -context ... Azfunctions += $FunctionObject ... Add a Binding object to an existing azFunction Object
Read more >
stub-azure-function-context - npm
Provides an object similar to Function Runtime's context for use in unit testing. Latest version: 2.0.0-alpha.7, last published: 4 months ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found