Call to undefined method Monolog\Logger::useFiles() when using php artisan snipeit:import
Please confirm you have done the following before posting your bug report:
- [x] I have enabled debug mode
- [X] I have read checked the Common Issues page
Describe the bug
Call to undefined method Monolog\Logger::useFiles() when using php artisan snipeit:import
To Reproduce Steps to reproduce the behavior:
- Go to CLI.
- Type
php artisan snipeit:import --item-type user --verbose --logfile ~/importer.log --update /home/myuser/user_test.csv - Experience Fatal Error (snip below).
Expected behavior CSV should import as expected.
Screenshots n/a
Server (please complete the following information):
- Snipe-IT Version: v5.0.6 build 5526 (g8a7cd8764)
- OS: Ubuntu 18.04
- Web Server: Apache
- PHP Version: 7.2.24-0ubuntu0.18.04.7
Error Messages
- Include the output from
php -m(this should display what modules you have enabled.)
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imagick
intl
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
- Stack trace:
$ php artisan snipeit:import --item-type user --verbose --logfile ~/importer.log --update ~/user_test.csv
In Logger.php line 273:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Monolog\Logger::useFiles()
Exception trace:
at /opt/inventory/vendor/laravel/framework/src/Illuminate/Log/Logger.php:273
Illuminate\Log\Logger->__call() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:630
Illuminate\Log\LogManager->__call() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:261
Illuminate\Support\Facades\Facade::__callStatic() at /opt/inventory/app/Console/Commands/ObjectImportCommand.php:59
App\Console\Commands\ObjectImportCommand->handle() at n/a:n/a
call_user_func_array() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32
Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Container/Util.php:36
Illuminate\Container\Util::unwrapIfClosure() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:90
Illuminate\Container\BoundMethod::callBoundMethod() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:34
Illuminate\Container\BoundMethod::call() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Container/Container.php:590
Illuminate\Container\Container->call() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Console/Command.php:134
Illuminate\Console\Command->execute() at /opt/inventory/vendor/symfony/console/Command/Command.php:255
Symfony\Component\Console\Command\Command->run() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Console/Command.php:121
Illuminate\Console\Command->run() at /opt/inventory/vendor/symfony/console/Application.php:1001
Symfony\Component\Console\Application->doRunCommand() at /opt/inventory/vendor/symfony/console/Application.php:271
Symfony\Component\Console\Application->doRun() at /opt/inventory/vendor/symfony/console/Application.php:147
Symfony\Component\Console\Application->run() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Console/Application.php:93
Illuminate\Console\Application->run() at /opt/inventory/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:131
Illuminate\Foundation\Console\Kernel->handle() at /opt/inventory/artisan:35
Additional context
- Is this a fresh install or an upgrade? fresh
- What OS and web server you're running Snipe-IT on Ubuntu 18.04/Apache
- What method you used to install Snipe-IT (install.sh, manual installation, docker, etc) manual
- Include what you've done so far in the installation, and if you got any error messages along the way. Imported assets and users through web interface just fine.
- Indicate whether or not you've manually edited any data directly in the database no
Looking at https://github.com/stevegrunwell/lost-in-translation/issues/6 referenced in https://github.com/snipe/snipe-it/issues/7035, it is mentioned that:
The new logging method (using Monolog) doesn't allow for changing the file "on the fly" anymore.
I also cannot find the method useFiles in the source code for Monolog\Logger.
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
@dmeltzer Does this look right to you? I only see that one instance of useFiles(), and I'm not sure I remember what it was used for (or how it ever worked?) I assume it was just used to create a log file of the results of the import, but without the original method, it's kinda hard to see what it's supposed to do here.
@kearneymo - if you comment out the useFiles() line in the ObjectImporter, does your import work?
@snipe, Yes, it works now. Well, it's at least giving me constructive feedback (field validation and stuff). Thanks for the fast response!
I commented out app/Console/Commands/ObjectImportCommand.php:59 as suggested.
public function handle()
{
$filename = $this->argument('filename');
$class = title_case($this->option('item-type'));
$classString = "App\\Importer\\{$class}Importer";
$importer = new $classString($filename);
$importer->setCallbacks([$this, 'log'], [$this, 'progress'], [$this, 'errorCallback'])
->setUserId($this->option('user_id'))
->setUpdating($this->option('update'))
->setShouldNotify($this->option('send-welcome'))
->setUsernameFormat($this->option('username_format'));
$logFile = $this->option('logfile');
// \Log::useFiles($logFile);
$this->comment('======= Importing Items from '.$filename.' =========');
$importer->import();
$this->bar = null;
if (!empty($this->errors)) {
$this->comment("The following Errors were encountered.");
foreach ($this->errors as $asset => $error) {
$this->comment('Error: Item: ' . $asset . ' failed validation: ' . json_encode($error));
}
} else {
$this->comment("All Items imported successfully!");
}
$this->comment("");
return;
}
@kearneymo TY for the quick feedback. I've pushed that change (the commenting out) to develop. I still need to further explore how to handle those import log files for now, but at least it should be working again.
This was a way of allowing all importer errors to be pushed to its own logfile. Given that the CLI importer was never as polished or used, and that feature was only for the CLI importer and never documented very well, it's probably simplest to just remove the option entirely.