1.1.33 • Published 2 years ago

beansio v1.1.33

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Beans (😏)

Logger for logging system events for Beansio

How to use beans to log middleware events

Remix.js Route logger Example

///init beans in the server.tsx file
import { plantBeans, remixRouteLogger,remixBeans } from 'beansio'

plantBeans('APII-KEY')
//init special remix functions

//set up sessions
const sessionStorage = createCookieSessionStorage({
  cookie: {
    name: "__session",
    httpOnly: true,
    maxAge: 0,
    path: "/",
    sameSite: "lax",
    secrets: [process.env.SESSION_SECRET || ''],
    secure: process.env.NODE_ENV === "production",
  },
});

//add middleware for remix
app.use(
    remixRouteLogger(

        async (req: any) => {
            const USER_SESSION_KEY = "userId";

            //this function sets user identifiers that can be stored on the db
            const cookie = req.headers['cookie']
            const session = await sessionStorage.getSession(cookie)
            const user =  session.get(USER_SESSION_KEY)

            return  user; ///optional customise return messages
        }
        , async (req: any) => {
            //this function lets users set custom meta data to be stored
            return {}; //set meta data
        }
    )
)   

Graphql example

import { plantBeans, graphQlLogger } from 'beansio'

plantBeans('APII-KEY')

const server = new GraphQLServer({
  schema,
  context: createContext,
  middlewares: [permissions],
})
server.express.use(

  graphQlLogger((req: any) => {
    //this function sets user identifiers that can be stored on the db
    if (!req.user) {
      return ""; //must be a string
    }
    return req.user.email || ""; ///optional customise return messages
  }, (req: any) => {
    //this function lets users set custom meta data to be stored
    return {}; //set meta data
  })
)
server.start(res => console.log(`We're live on port ${res.port}`));

Express Example

const express = require('express')
const app = express()
const port = 3100
//import beans library
import { plantBeans, routeLogger } from 'beansio'

plantBeans('APII-KEY')

//Calling the ExpressBeans function to log all 
app.use(routeLogger(  (req )=>{
  //this function sets user identifiers that can be stored on the db
 

  if ( !req.user) {
      return ""; //must be a string
  }

   return req.user.email || ""; ///optional customise return messages
} ,(req)=>{
   //this function lets users set custom meta data to be stored
   return  {}; //set meta data
}))




app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

How to use beans to log Custom messages

    const event = () =>{
        ///perfom operation
        beans.logMessage('Event triggered by user ',{})
    }

How to use beans to log an error event

    const startJokeServer =   () =>{
        app.listen(port, () => {
           //////
        }).on('error', (error) => {
            beans.logError('Error starting server',{})
        });
    }

How to use beans as an error handler

    // Error fallback
    import { plantBeans, beansErrorHandler } from 'beansio'

    plantBeans('APII-KEY')
    ///
    ///
    app.use(beansErrorHandler);
    

beansio

beansio

1.1.33

2 years ago

1.1.32

2 years ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.30

2 years ago

1.1.31

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.1.27

2 years ago

1.1.26

2 years ago

1.1.25

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.910

3 years ago

1.0.920

3 years ago

1.0.8

3 years ago

1.0.900

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.90

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

3 years ago

1.1.13

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago