warp-id / solana-trading-bot

Solana Trading Bot - Beta
Microsoft Public License
1.27k stars 580 forks source link

Logs #139

Open NukeThemAII opened 2 weeks ago

NukeThemAII commented 2 weeks ago

Hi, anyway to store console logs to file?

I use npm run start > botxxx.log

But with that no live console logs.

edujr1 commented 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

Ismola commented 4 days ago

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);
//     }
//   });
// };