Open NukeThemAII opened 2 weeks ago
If you use Unix, try this
npm run start | tee botxxx.log
If use windows
npm install -g wintee
and
npm run start | wintee botxxx.log
In helpers/logger.ts
import pino from 'pino';
import { io } from '..';
import { saveLog } from '../controllers/LogControllers';
// Set up a transport for pretty printing logs
const socketIoTransport = {
write: async (log: any) => {
try {
await saveLog(JSON.parse(log));
} catch (error) {
console.error('Error saving log:', error);
}
io.emit('message', log);
}
};
// Create a Pino logger instance
export const logger = pino(
{
level: 'debug', // Set log level to 'info'
redact: ['poolKeys'], // Redact 'poolKeys' from logs for security/privacy
serializers: {
error: pino.stdSerializers.err, // Use standard error serializer
},
base: undefined, // Omit base properties like 'pid' and 'hostname' from logs
},
socketIoTransport // Use the custom transport
);
// Make a function to save logs ina file
// export const saveLog = (log: any) => {
// const fs = require('fs');
// const logFile = 'logs.txt';
// const logString = JSON.stringify(log) + '\n';
// fs.appendFile(logFile, logString, (err) => {
// if (err) {
// console.error('Error saving log:', err);
// }
// });
// };
Hi, anyway to store console logs to file?
I use npm run start > botxxx.log
But with that no live console logs.