diff --git a/app/Jobs/DiscoverDevice.php b/app/Jobs/DiscoverDevice.php index 6195e2842a81..bba8da5e97a2 100644 --- a/app/Jobs/DiscoverDevice.php +++ b/app/Jobs/DiscoverDevice.php @@ -61,7 +61,7 @@ public function handle(): void $this->device->device_id, $measurement->getDuration())); - Log::channel('log_file')->alert(sprintf('INFO: device:discover %s (%s) discovered in %0.3fs', + Log::alert(sprintf('INFO: device:discover %s (%s) discovered in %0.3fs', $this->device->hostname, $this->device->device_id, $measurement->getDuration())); diff --git a/app/Jobs/PollDevice.php b/app/Jobs/PollDevice.php index 9922c0bdf2b0..98fe523f9e0a 100644 --- a/app/Jobs/PollDevice.php +++ b/app/Jobs/PollDevice.php @@ -94,7 +94,7 @@ public function handle(): void $measurement->getDuration())); // add log file line, this is used by the simple python dispatcher watchdog - Log::channel('log_file')->alert(sprintf('INFO: device:poll %s (%s) polled in %0.3fs', + Log::alert(sprintf('INFO: device:poll %s (%s) polled in %0.3fs', $this->device->hostname, $this->device->device_id, $measurement->getDuration())); diff --git a/app/Observers/ModuleModelObserver.php b/app/Observers/ModuleModelObserver.php index 917d35d15946..37d7ef33d170 100644 --- a/app/Observers/ModuleModelObserver.php +++ b/app/Observers/ModuleModelObserver.php @@ -52,7 +52,7 @@ public static function observe($model, string $name = ''): void $class = ltrim($model, '\\'); if ($name) { - Log::channel('stdout')->info(ucwords($name) . ': ', ['nlb' => true]); + Log::info(ucwords($name) . ': ', ['nlb' => true]); } if (! in_array($class, $observed_models)) { @@ -63,7 +63,7 @@ public static function observe($model, string $name = ''): void public static function done(): void { - Log::channel('stdout')->info(PHP_EOL, ['nlb' => true]); + Log::info(PHP_EOL, ['nlb' => true]); } /** diff --git a/discovery.php b/discovery.php index 5534e4e8da86..94b9862c6f7b 100755 --- a/discovery.php +++ b/discovery.php @@ -138,7 +138,7 @@ app(\App\Polling\Measure\MeasurementManager::class)->printStats(); } -logfile($string); +Log::debug($string); if ($doing !== 'new' && $discovered_devices == 0) { // No discoverable devices, either down or disabled diff --git a/includes/functions.php b/includes/functions.php index 1c2555963941..e592cc9d5fce 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -64,21 +64,6 @@ function parse_modules($type, $options) return $override; } -function logfile($string) -{ - $file = LibrenmsConfig::get('log_file'); - $fd = fopen($file, 'a'); - - if ($fd === false) { - print_error("Error: Could not write to log file: $file"); - - return; - } - - fwrite($fd, $string . "\n"); - fclose($fd); -} - function renamehost($id, $new, $source = 'console') { $host = gethostbyid($id); diff --git a/poll-billing.php b/poll-billing.php index a93e7d3f00bd..e3be9708f52a 100755 --- a/poll-billing.php +++ b/poll-billing.php @@ -31,14 +31,12 @@ $scheduler = LibrenmsConfig::get('schedule_type.billing'); if (! isset($options['f']) && $scheduler != 'legacy' && $scheduler != 'cron') { - if (Debug::isEnabled()) { - echo "Billing is not enabled for cron scheduling. Add the -f command argument if you want to force this command to run.\n"; - } + Log::debug('Billing is not enabled for cron scheduling. Add the -f command argument if you want to force this command to run.'); exit(0); } $poller_start = microtime(true); -echo "Starting Polling Session ... \n\n"; +Log::info("Starting Bill Polling Session ... \n"); $query = \LibreNMS\DB\Eloquent::DB()->table('bills'); @@ -47,7 +45,7 @@ } foreach ($query->get(['bill_id', 'bill_name']) as $bill) { - echo 'Bill : ' . $bill->bill_name . "\n"; + Log::info('Bill : ' . $bill->bill_name); $bill_id = $bill->bill_id; if (LibrenmsConfig::get('distributed_poller') && LibrenmsConfig::get('distributed_billing')) { @@ -65,7 +63,7 @@ $host = $port_data['hostname']; $port = $port_data['port']; - echo " Polling {$port_data['ifName']} ({$port_data['ifDescr']}) on {$port_data['hostname']}\n"; + Log::info(" Polling {$port_data['ifName']} ({$port_data['ifDescr']}) on {$port_data['hostname']}"); $port_data['in_measurement'] = Billing::getValue($port_data['hostname'], $port_data['port'], $port_data['ifIndex'], 'In'); $port_data['out_measurement'] = Billing::getValue($port_data['hostname'], $port_data['port'], $port_data['ifIndex'], 'Out'); @@ -99,17 +97,13 @@ $port_data['out_delta'] = '0'; } //////////////////////////////////CountersValidation$DB-Update - echo "\nDB SNMP counters received.\n"; - echo ' in_measurement: ',$port_data['in_measurement'],' out_measurement: ',$port_data['out_measurement'],"\n"; - echo ' The data types are --> in_measurement:' . gettype($port_data['in_measurement']) . ' and out_measurement: ' . gettype($port_data['out_measurement']) . "\n"; //For debugging - logfile("\n****$now: " . $bill->bill_name . "\nDB SNMP counters received."); - logfile('in_measurement: ' . $port_data['in_measurement'] . ' out_measurement: ' . $port_data['out_measurement'] . "\nThe data types are. in_measurement:" . gettype($port_data['in_measurement']) . ' and out_measurement: ' . gettype($port_data['out_measurement'])); - logfile('IN_delta: ' . $port_data['in_delta'] . ' OUT_delta: ' . $port_data['out_delta'] . "\nLast_IN_delta: " . ($port_data['last_in_delta'] ?? '') . ' last_OUT_delta: ' . ($port_data['last_out_delta'] ?? '')); + Log::debug("****$now: " . $bill->bill_name . ' Billing DB SNMP counters received.'); + Log::debug('in_measurement: ' . $port_data['in_measurement'] . ' out_measurement: ' . $port_data['out_measurement'] . "\nThe data types are. in_measurement:" . gettype($port_data['in_measurement']) . ' and out_measurement: ' . gettype($port_data['out_measurement'])); + Log::debug('IN_delta: ' . $port_data['in_delta'] . ' OUT_delta: ' . $port_data['out_delta'] . "\nLast_IN_delta: " . ($port_data['last_in_delta'] ?? '') . ' last_OUT_delta: ' . ($port_data['last_out_delta'] ?? '')); if (is_numeric($port_data['in_measurement']) && is_numeric($port_data['out_measurement'])) { - echo "Nice, valid counters 'in/out_measurement', lets use them\n"; - logfile("Nice, valid counters 'in/out_measurement', lets use them"); + Log::debug("Nice, valid counters 'in/out_measurement', lets use them"); // NOTE: casting to string for mysqli bug (fixed by mysqlnd) $fields = ['timestamp' => $now, 'in_counter' => (string) set_numeric($port_data['in_measurement']), 'out_counter' => (string) set_numeric($port_data['out_measurement']), 'in_delta' => (string) set_numeric($port_data['in_delta']), 'out_delta' => (string) set_numeric($port_data['out_delta'])]; if (dbUpdate($fields, 'bill_port_counters', "`port_id`='" . $port_id . "' AND `bill_id`='$bill_id'") == 0) { @@ -118,8 +112,7 @@ dbInsert($fields, 'bill_port_counters'); } } else { - echo "WATCH out! - Wrong counters. Table 'bill_port_counters' not updated\n"; - logfile("WATCH out! - Wrong counters. Table 'bill_port_counters' not updated"); + Log::error("WATCH out! - Wrong counters. Table 'bill_port_counters' not updated"); } ////////////////////////////////EndCountersValidation&DB-Update $delta = ($delta + $port_data['in_delta'] + $port_data['out_delta']); @@ -149,7 +142,7 @@ } if (! empty($period) && $period < '0') { - logfile("BILLING: negative period! id:$bill_id period:$period delta:$delta in_delta:$in_delta out_delta:$out_delta"); + Log::debug("BILLING: negative period! id:$bill_id period:$period delta:$delta in_delta:$in_delta out_delta:$out_delta"); } else { // NOTE: casting to string for mysqli bug (fixed by mysqlnd) if (LibrenmsConfig::get('distributed_poller') && LibrenmsConfig::get('distributed_billing')) { @@ -169,8 +162,8 @@ $poller_time = substr($poller_run, 0, 5); if ($poller_time > 300) { - logfile("BILLING: polling took longer than 5 minutes ($poller_time seconds)!"); + Log::warning("BILLING: polling took longer than 5 minutes ($poller_time seconds)!"); } -echo "\nCompleted in $poller_time sec\n"; +Log::info("Completed in $poller_time sec"); app('Datastore')->terminate(); diff --git a/syslog.php b/syslog.php index fb1cfe3aeabe..8016cf0881b9 100755 --- a/syslog.php +++ b/syslog.php @@ -15,7 +15,7 @@ $s = fopen('php://stdin', 'r'); while ($line = fgets($s)) { - //logfile($line); + // Log::channel('log_file')->critical($line); // uncomment to log input to librenms.log $fields = explode('||', trim($line)); if (count($fields) === 8) {