0.0.18 • Published 1 year ago

cloud-app-logger v0.0.18

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Adding Cloud Logging to Express Application

This guide explains how to integrate cloud logging into your Express application using the cloud-app-logger library. Each log will include a unique request ID for tracking the entire journey of a request, including request body, response, and any additional logs or errors for that request.

Note: Currently, only Google Cloud Logging is supported.

Steps to Add Cloud Logging

  1. Add the following to your package.json:

    "cloud-app-logger": "^0.0.17"
  2. Add the following environment variables:

    LOGGING_PROJECT_ID=<YOUR_PROJECT_ID> # Name for the Google Cloud project where logs should be stored
    LOGGING_ENABLED=true # Enable logs being sent to the cloud. Keep false when running local code
    LOGGING_LOG_NAME=<LOG_NAME> # Log name in Google Cloud. For example, app-name-staging
  3. Import the necessary functions wherever your Express app object is created:

    import { initAppLogger, configureErrorLogging, configureRequestLogging } from 'cloud-app-logger';
    
    // Call this as early as possible but after calling dotenv.config()
    initAppLogger();
  4. After adding body parsing middlewares such as json or urlencoded, configure request logging:

    app.use(express.json());
    app.use(express.urlencoded({ extended: false }));
    
    // Call the function here !!!
    configureRequestLogging(app);
  5. Call the error logging configuration function after adding all middlewares/routes:

    configureErrorLogging(app);
  6. Call the logUnhandledExceptions function in each file where you have defined a router after importing Router or Express:

    import { Router, Request, Response } from 'express';
    import { logUnhandledExceptions } from 'cloud-app-logger';
    
    // Call the function here
    logUnhandledExceptions();
    
    const router = Router();
  7. Run the project, and logging should now be enabled and visible in Google Cloud Logging.

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.1

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago