Open SirMishaa opened 2 months ago
Note that I've tried without all customLevels and levels things, but result is the same, I don't get any logs below the info level
Here's my simple setup, hope it helps.
import 'dotenv/config';
import express from 'express';
import { pino, transport } from 'pino';
const APP_PORT = process.env.APP_PORT || 3333;
const LOKI_HOST = process.env.LOKI_HOST || 'http://localhost:3100';
const app = express();
app.set('name', 'pino-loki-example');
const environment = process.env.NODE_ENV || 'development';
const production = environment === 'production';
// const loadNs = process.hrtime()
// const loadMs = new Date().getTime()
// function nanoseconds() {
// const diffNs = process.hrtime(loadNs)
// return BigInt(loadMs) * BigInt(1e6) + BigInt(diffNs[0] * 1e9 + diffNs[1])
// }
const level = production ? 'info' : 'trace';
const multiTransport = transport({
targets: [
{
target: 'pino-loki',
level,
options: {
batching: false,
host: LOKI_HOST,
labels: {
app: app.get('name'),
stream: environment
},
},
},
{
target: 'pino-pretty',
level,
options: {
formatter: 'pretty',
colorize: true,
translateTime: 'SYS:standard',
},
},
]
})
const logger = pino(
{
level,
// timestamp: () => `,"time":${nanoseconds()}`,
},
multiTransport
)
app.get('/', (req, res) => {
logger.trace('Trace!')
logger.debug('Debug!')
logger.info('Info!')
logger.warn('Warn!')
logger.error('Error!')
logger.fatal('Fatal!')
res.send('Hello World!');
});
app.listen(APP_PORT, () => {
console.log(`Server is running on port ${APP_PORT}`);
});
Console: Grafana:
Now, you might notice how the ordering in Grafana is messed up. 😄 The logs go up so fast that the timestamp is the same, no joke :) You might need nanoseconds on your entries, but keep in mind it will add some overhead. Uncomment the commented out code and you will get the correct order. For more reference: GitHub Issue
Hello,
First, thank you for your package, it's working good !
I have just a small question, I'd to see log with level debug / trace, but I cannot see it on Grafana
Result is :
I guess I'm missing something in the configuration of pino or of the transport itself See the configuration for pino :
Best regards