Logger for logging system events for Beansio
///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
}
)
)
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}`));
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}`)
})
const event = () =>{
///perfom operation
beans.logMessage('Event triggered by user ',{})
}
const startJokeServer = () =>{
app.listen(port, () => {
//////
}).on('error', (error) => {
beans.logError('Error starting server',{})
});
}
// Error fallback
import { plantBeans, beansErrorHandler } from 'beansio'
plantBeans('APII-KEY')
///
///
app.use(beansErrorHandler);