0.1.0 • Published 5 years ago

@pexxi/winston-azure-functions v0.1.0

Weekly downloads
199
License
MIT
Repository
github
Last release
5 years ago

winston-azure-functions

Build Status Dependencies Status

This is a fork of https://github.com/upcompass/winston-azure-functions with TypeScript build errors fixed.

Basically, this transport pipes all output to Azure Functions' context.log().

How to use

Setup

Install with npm:

npm install --save @pexxi/winston-azure-functions

or with Yarn:

yarn add @pexxi/winston-azure-functions

Usage

Create a logger component, where you can configure Winston:

import { Context } from "@azure/functions";
import { AzureFunctions } from "winston-azure-functions";
import winston = require("winston");

export const configure = (context: Context) => {
  winston.configure({
    transports: [new AzureFunctions({ context })],
  });
};

export default winston;

In your function, call configure first passing function context as parameter:

import { Context } from '@azure/functions'
import logger, { configureLogger } from "../src/utils/logger";
...
module.exports = function(context: Context) {
  configureLogger(context)
  // rest of the function code...
  logger.info("Logging some stuff...")
};

Now you can use it in the rest of your code, e.g.:

import logger from "./logger"

...

logger.info("Logging on info level...")

Just remember to configure your logger in each function before using it anywhere else during the execution.

Supported log levels

Log levelDescription
errorWrites to error level logging, or lower.
warnWrites to warning level logging, or lower.
infoWrites to info level logging, or lower.
verboseWrites to verbose level logging.