chore(backend): Loki configureren
De meeste console statements vervangen door Loki
This commit is contained in:
parent
0f8bd3df6a
commit
7fd6305fd9
8 changed files with 767 additions and 40 deletions
|
@ -1,11 +1,21 @@
|
|||
import express, { Express, Response } from 'express';
|
||||
import initORM from './orm.js';
|
||||
import { getLogger } from './logging/initalize.js';
|
||||
import { responseTimeLogger } from './logging/responseTimeLogger.js';
|
||||
import responseTime from 'response-time';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
const logger: Logger = getLogger();
|
||||
|
||||
const app: Express = express();
|
||||
const port: string | number = process.env.PORT || 3000;
|
||||
|
||||
app.use(express.json());
|
||||
app.use(responseTime(responseTimeLogger));
|
||||
|
||||
// TODO Replace with Express routes
|
||||
app.get('/', (_, res: Response) => {
|
||||
logger.debug('GET /');
|
||||
res.json({
|
||||
message: 'Hello Dwengo!',
|
||||
});
|
||||
|
@ -15,35 +25,8 @@ async function startServer() {
|
|||
await initORM();
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is running at http://localhost:${port}`);
|
||||
logger.info(`Server is running at http://localhost:${port}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
import { LokiClient, LogError, LokiLabels, LogInfo } from 'loki-logger-ts';
|
||||
|
||||
const HostData = {
|
||||
url: "http://localhost:3100/loki/api/v1/push",
|
||||
};
|
||||
|
||||
const labels: LokiLabels = {
|
||||
source: "Test",
|
||||
job: "TestJob",
|
||||
host: "localhost",
|
||||
};
|
||||
|
||||
async function main() {
|
||||
const client = new LokiClient(HostData.url);
|
||||
|
||||
const msg = 'Hello World';
|
||||
await LogError(client, msg, labels);
|
||||
await LogInfo(client, 'Dit is een goed bericht', labels);
|
||||
|
||||
console.log(client.showMetrics());
|
||||
|
||||
console.log(client.getMetrics());
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
// startServer();
|
||||
startServer();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue