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

Fix handling of logger calls in lib/private/Log.php #40844

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/40844
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: verbose command output

Verbose command output of the background:queue:execute is now displayed.

https://github.com/owncloud/core/pull/40844
8 changes: 6 additions & 2 deletions lib/private/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,15 @@ public function log($level, $message, array $context = []) {

if ($level >= $minLevel) {
$logger = $this->logger;
// check if logger supports extra fields
// check if logger supports extra fields, and which method is available
if (!empty($extraFields) && \is_callable([$logger, 'writeExtra'])) {
\call_user_func([$logger, 'writeExtra'], $app, $formattedMessage, $level, $logConditionFile, $extraFields);
} else {
} elseif (\is_callable([$logger, 'write'])) {
\call_user_func([$logger, 'write'], $app, $formattedMessage, $level, $logConditionFile);
} elseif (\is_callable([$logger, 'log'])) {
\call_user_func([$logger, 'log'], $level, $formattedMessage, $context);
} else {
throw new \Exception("No logger method available. Trying to log message '$formattedMessage'.");
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ default:
contexts:
- FeatureContext: *common_feature_context_params
- OccContext:
- LoggingContext:

cliCreateLocalStorage:
paths:
Expand Down
28 changes: 28 additions & 0 deletions tests/acceptance/features/bootstrap/OccContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,22 @@ public function deleteExpiredVersionsForAllUsersUsingOccCommand(): void {
$this->deleteExpiredVersionsForUserUsingOccCommand();
}

/**
* @param string $job
*
* @return void
* @throws Exception
*/
public function executeLastBackgroundJobUsingTheOccCommand(string $job):void {
$match = $this->getLastJobIdForJob($job);
if ($match === false) {
throw new Exception("Couldn't find jobId for given job: $job");
}
$this->invokingTheCommand(
"background:queue:execute --accept-warning --force -vvv $match"
);
}

/**
* @param string $job
*
Expand Down Expand Up @@ -2891,6 +2907,18 @@ public function theAdministratorGetsAllTheJobsInTheBackgroundQueueUsingTheOccCom
$this->getAllJobsInBackgroundQueueUsingOccCommand();
}

/**
* @When the administrator executes the last background job :job using the occ command
*
* @param string $job
*
* @return void
* @throws Exception
*/
public function theAdministratorExecutesLastBackgroundJobUsingTheOccCommand(string $job):void {
$this->executeLastBackgroundJobUsingTheOccCommand($job);
}

/**
* @When the administrator deletes the last background job :job using the occ command
*
Expand Down
20 changes: 17 additions & 3 deletions tests/acceptance/features/cliBackground/backgroundQueue.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@cli @files_trashbin-app-required @files_sharing-app-required @skipOnLDAP
Feature: get status, delete and execute jobs in background queue
As an admin
I want to be able to see, delete and execute the jobs in background queue
So that I have control over background job queue
I want to be able to see, delete and execute jobs in the background queue
So that I have control over the background job queue


Scenario: get the list of jobs in background queue
Expand All @@ -24,9 +24,23 @@ Feature: get status, delete and execute jobs in background queue
| OC\Authentication\Token\DefaultTokenCleanupJob |


Scenario: delete one of the job in background queue
Scenario: delete one of the jobs in the background queue
Given user "Alice" has been created with default attributes and small skeleton files
And user "Alice" has deleted file "/textfile0.txt"
When the administrator deletes the last background job "OC\Command\CommandJob" using the occ command
Then the command should have been successful
And the last deleted background job "OC\Command\CommandJob" should not be listed in the background jobs queue


Scenario: execute one of the jobs in the background queue
Given user "Alice" has been created with default attributes and small skeleton files
And user "Alice" has deleted file "/textfile0.txt"
And the owncloud log level has been set to debug
When the administrator executes the last background job "OCA\Files\BackgroundJob\ScanFiles" using the occ command
Then the command should have been successful
And the command output should contain the text "Found job: OCA\Files\BackgroundJob\ScanFiles with ID"
And the command output should contain the text "Forcing run, resetting last run value to 0"
And the command output should contain the text "Running job..."
And the command output should contain the text "Started background job of class : OCA\Files\BackgroundJob\ScanFiles with arguments :"
And the command output should contain the text "Finished background job"
And the command output should contain the text "this job is an instance of class : OCA\Files\BackgroundJob\ScanFiles with arguments :"