Giter VIP home page Giter VIP logo

karannagupta / loopback4-express-with-logging Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 2.0 73 KB

An example of integrating Winston & Morgan Logging with Loopback 4. It uses the express-composition example that mounts the LoopBack 4 REST API on a simple Express Application

Home Page: https://karannagupta.com/mounting-loopback-4-rest-api-in-express-with-winston-logging/

License: Other

Dockerfile 0.97% JavaScript 3.90% HTML 17.29% TypeScript 77.84%
loopback4 winston-logger loopback express-loopback4

loopback4-express-with-logging's Introduction

loopback4-express-with-logging

This is an example of integrating Winston & Morgan Logging with Loopback 4. It uses the express-composition example that mounts the LoopBack 4 REST API on a simple Express application. See here for the express-composition example.

The Express application in this example is based on the Express Generator

You'll need to install the LoopBack 4 CLI toolkit to scaffold your own application:

npm i -g @loopback/cli

Express-Composition Tutorial

You can begin by visiting the official tutorial page for mounting Loopback 4 in Express.

Try out this example

If you'd like to see the final results of this tutorial as an example application, follow these steps:

  1. Download/Clone this project.

  2. Jump into the directory and then install the required dependencies:

    cd loopback4-express-with-logging
    npm install
  3. Finally, start the application!

    $ npm start
    
    Server is running at http://127.0.0.1:8000
  4. Open the Loopback Explorer at http://127.0.0.1:8000/api/explorer/

Feel free to look around in the application's code to get a feel for how it works.

Winston Logging Example

import { winstonLogger } from "./lib/logger";
// log the error.
winstonLogger.error(
  `${err.status || 500} - ${err.message} - ${req.originalUrl} - ${
    req.method
  } - ${req.ip}`
);

Winston Logging Endpoint Example

You can use the /errorlogger endpoint to log an error from your front end application as well -

curl -X POST "http://127.0.0.1:8000/api/errorlogger" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"message\":\"My awesome error message\"}"

Log Files

Log files are separated out based on the log levels. The logs directory is generated at run time.

Docker

Application works with Docker. Use the docker-compose to create your Docker container.

Screenshots

1. Log Files

Log Files

2. Error Logger endpoint - /api/errorlogger - POST

errorlogger endpoint

License

MIT

loopback4-express-with-logging's People

Contributors

karannagupta avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.