Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs #139

Open
NukeThemAII opened this issue Jun 18, 2024 · 2 comments
Open

Logs #139

NukeThemAII opened this issue Jun 18, 2024 · 2 comments

Comments

@NukeThemAII
Copy link

NukeThemAII commented Jun 18, 2024

Hi, anyway to store console logs to file?

I use npm run start > botxxx.log

But with that no live console logs.

@edujr1
Copy link

edujr1 commented Jun 18, 2024

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
Copy link

Ismola commented Jun 28, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants