Skip to main content

Add your own logs

Custom log files in Gunbot custom strategies provide enhanced insights into your trading bot's activities. This guide details the process of implementing custom logs, enabling you to create log content to your specific requirements.


Before beginning, ensure you have basic knowledge of Node.js, specifically working with the file system (fs module).

Implementing Custom Logs

Follow these steps to add custom log files to Gunbot:

1. Access the File System

Utilize Node.js' fs module to interact with the file system. This module offers various methods for file operations.

2. Create a Write Stream

Establish a write stream for appending data to your log file using the fs.createWriteStream method.

3. Write to the Log File

With the write stream set up, you can begin logging data. Append information to your log as needed.

Example Code

The following JavaScript snippet demonstrates the process:

// Importing the file system module
const fs = gb.method.require('fs')

// Setting up a write stream to a custom log file
const logger = fs.createWriteStream('./gunbot_logs/custom-logs.txt', {flags: 'a'});

// Writing a sample log entry
logger.write(`\nCustom Log Entry: ${new Date().toISOString()}`);

This example illustrates a basic implementation. You can extend this to suit more complex logging requirements.


Custom logs in Gunbot empower you to track and analyze your trading bot's performance effectively. Experiment and adapt the approach to fit your unique trading strategy.