Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | #!/usr/bin/env node
const { Command } = require('commander');
const path = require('path');
const fs = require('fs');
const os = require('os');
const program = new Command();
// Get version from package.json
const packageJson = require('../package.json');
program
.name('logvista')
.description('LogVista Agent - Universal monitoring for any language/project')
.version(packageJson.version);
// Global config directory
const getConfigDir = () => {
const platform = os.platform();
if (platform === 'win32') {
return path.join(os.homedir(), 'AppData', 'Roaming', 'LogVista');
} else {
return path.join(os.homedir(), '.logvista');
}
};
const getConfigPath = () => path.join(getConfigDir(), 'agent.config.json');
// Init command - Initialize LogVista in current directory
program
.command('init')
.description('Initialize LogVista monitoring in current directory')
.option('-u, --url <url>', 'Central system URL', 'http://localhost:3001')
.option('-t, --token <token>', 'Agent authentication token')
.option('-n, --name <name>', 'Project name', path.basename(process.cwd()))
.action(async (options) => {
const currentDir = process.cwd();
const projectName = options.name;
console.log(`š Initializing LogVista monitoring for: ${projectName}`);
console.log(`š Project directory: ${currentDir}`);
// Create local config
const localConfig = {
central_system: {
url: options.url,
token: options.token || 'your-agent-token-here'
},
collection: {
interval: 30,
batch_size: 100,
retry_attempts: 3,
retry_delay: 5000
},
projects: [
{
project_name: projectName,
pwd_path: currentDir,
custom_log_paths: [
// Common log patterns for different languages
path.join(currentDir, 'logs', '*.log'),
path.join(currentDir, 'log', '*.log'),
path.join(currentDir, 'storage', 'logs', '*.log'), // Laravel PHP
path.join(currentDir, 'var', 'log', '*.log'), // Symfony PHP
path.join(currentDir, 'Logs', '*.log'), // .NET
path.join(currentDir, 'bin', 'Debug', 'netcoreapp*', '*.log'), // .NET Core
path.join(currentDir, '*.log'), // Go, Python, Node.js in root
path.join(currentDir, 'tmp', '*.log'), // Rails Ruby
path.join(currentDir, 'log', '**', '*.log') // Nested logs
].filter(logPath => {
// Check if any of these paths exist
const globPattern = logPath.replace('*', '');
const dir = path.dirname(globPattern);
return fs.existsSync(dir);
}),
enabled: true
}
]
};
// Create .logvista directory if it doesn't exist
const logvistaDir = path.join(currentDir, '.logvista');
if (!fs.existsSync(logvistaDir)) {
fs.mkdirSync(logvistaDir);
}
// Write local config
const localConfigPath = path.join(logvistaDir, 'config.json');
fs.writeFileSync(localConfigPath, JSON.stringify(localConfig, null, 2));
// Create .gitignore entry
const gitignorePath = path.join(currentDir, '.gitignore');
const gitignoreEntry = '\n# LogVista\n.logvista/\n';
if (fs.existsSync(gitignorePath)) {
const gitignoreContent = fs.readFileSync(gitignorePath, 'utf8');
if (!gitignoreContent.includes('.logvista/')) {
fs.appendFileSync(gitignorePath, gitignoreEntry);
console.log('ā
Added .logvista/ to .gitignore');
}
} else {
fs.writeFileSync(gitignorePath, gitignoreEntry);
console.log('ā
Created .gitignore with LogVista entries');
}
console.log('ā
LogVista configuration created successfully!');
console.log(`š Config file: ${localConfigPath}`);
console.log('\nš Next steps:');
console.log('1. Update the agent token in the config file');
console.log('2. Run "logvista start" to begin monitoring');
console.log('3. Check "logvista status" to verify everything is working');
});
// Start command - Start monitoring
program
.command('start')
.description('Start LogVista monitoring')
.option('-d, --daemon', 'Run as daemon process')
.option('-c, --config <path>', 'Custom config file path')
.action((options) => {
const currentDir = process.cwd();
const configPath = options.config || path.join(currentDir, '.logvista', 'config.json');
if (!fs.existsSync(configPath)) {
console.error('ā No LogVista configuration found!');
console.log('Run "logvista init" first to initialize monitoring.');
process.exit(1);
}
console.log('š Starting LogVista Agent...');
console.log(`š Using config: ${configPath}`);
// Set environment variable for the agent to use this config
process.env.LOGVISTA_CONFIG_PATH = configPath;
// Start the agent
require('../src/index.js');
});
// Status command - Check agent status
program
.command('status')
.description('Check LogVista agent status')
.action(() => {
const currentDir = process.cwd();
const configPath = path.join(currentDir, '.logvista', 'config.json');
if (!fs.existsSync(configPath)) {
console.log('ā LogVista not initialized in this directory');
console.log('Run "logvista init" to get started');
return;
}
console.log('š LogVista Status:');
console.log(`š Project: ${path.basename(currentDir)}`);
console.log(`š Config: ${configPath}`);
try {
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
console.log(`š Central System: ${config.central_system.url}`);
console.log(`š Token: ${config.central_system.token ? 'ā
Configured' : 'ā Missing'}`);
console.log(`š Projects: ${config.projects.length}`);
config.projects.forEach((project, index) => {
console.log(` ${index + 1}. ${project.project_name} (${project.enabled ? 'enabled' : 'disabled'})`);
console.log(` š Path: ${project.pwd_path}`);
console.log(` š Log paths: ${project.custom_log_paths.length} configured`);
});
} catch (error) {
console.error('ā Error reading config:', error.message);
}
});
// Stop command - Stop monitoring
program
.command('stop')
.description('Stop LogVista monitoring')
.action(() => {
console.log('š Stopping LogVista Agent...');
// In a real implementation, this would send a signal to stop the daemon
// For now, we'll just show the message
console.log('ā
LogVista Agent stopped');
});
// Config command - Manage configuration
program
.command('config')
.description('Manage LogVista configuration')
.option('--show', 'Show current configuration')
.option('--edit', 'Edit configuration file')
.option('--set <key=value>', 'Set configuration value')
.action((options) => {
const currentDir = process.cwd();
const configPath = path.join(currentDir, '.logvista', 'config.json');
if (!fs.existsSync(configPath)) {
console.error('ā No LogVista configuration found!');
console.log('Run "logvista init" first to initialize monitoring.');
return;
}
if (options.show) {
console.log('š Current Configuration:');
const config = fs.readFileSync(configPath, 'utf8');
console.log(config);
} else if (options.edit) {
console.log(`š Opening config file: ${configPath}`);
console.log('Edit the file and save when done.');
// In a real implementation, this could open the default editor
} else {
console.log('Use --show to view config or --edit to modify it');
}
});
// Global install/setup
program
.command('install')
.description('Install LogVista globally (admin/sudo required)')
.action(() => {
console.log('š§ Installing LogVista globally...');
console.log('This command sets up LogVista for system-wide use.');
const configDir = getConfigDir();
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true });
console.log(`ā
Created config directory: ${configDir}`);
}
// Create a default global config if it doesn't exist
const globalConfigPath = getConfigPath();
if (!fs.existsSync(globalConfigPath)) {
const defaultConfig = {
central_system: {
url: 'http://localhost:3001',
token: 'your-global-agent-token-here'
},
collection: {
interval: 30,
batch_size: 100,
retry_attempts: 3,
retry_delay: 5000
},
projects: []
};
fs.writeFileSync(globalConfigPath, JSON.stringify(defaultConfig, null, 2));
console.log(`ā
Created global config: ${globalConfigPath}`);
}
console.log('ā
LogVista installed successfully!');
console.log('\nš Next steps:');
console.log('1. Navigate to any project directory');
console.log('2. Run "logvista init" to set up monitoring');
console.log('3. Run "logvista start" to begin monitoring');
});
// Help examples
program.on('--help', () => {
console.log('');
console.log('Examples:');
console.log(' $ logvista init # Initialize in current directory');
console.log(' $ logvista init --name "MyApp" # Initialize with custom name');
console.log(' $ logvista start # Start monitoring');
console.log(' $ logvista status # Check status');
console.log(' $ logvista config --show # Show configuration');
console.log('');
console.log('Supported Languages/Frameworks:');
console.log(' ⢠Node.js, Python, Go, Rust');
console.log(' ⢠PHP (Laravel, Symfony, etc.)');
console.log(' ⢠.NET Core/.NET Framework');
console.log(' ⢠Java (Spring Boot, etc.)');
console.log(' ⢠Ruby (Rails, etc.)');
console.log(' ⢠Any application that writes to log files');
});
program.parse();
|