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

Logging to a file using relative path fails in cli mode #10551

Closed
3 of 4 tasks
romain-louis opened this issue Oct 18, 2022 · 6 comments
Closed
3 of 4 tasks

Logging to a file using relative path fails in cli mode #10551

romain-louis opened this issue Oct 18, 2022 · 6 comments

Comments

@romain-louis
Copy link

romain-louis commented Oct 18, 2022

Affected Version

4.11

Description

The documentation mentions to use a relative path to log on file.
This works on browser but not using command line.
It causes the following error:
ERROR [Emergency]: Uncaught UnexpectedValueException: The stream or file "/var/www/../silverstripe.log" could not be opened in append mode

Steps to Reproduce

Using the command line run a CliController class or BuildTask class which itself "raises logging diagnostic information"

Acceptance criteria

  • For CMS 4: Update docs to explicitly use an absolute path.
  • For CMS 5: Update doc to explicitely use an absolute path until we come up with a better solution in consultation with our hosting team
  • For CMS 5: Investigate ways to make the relative path work the same regardless of whether you're using CLI or HTTP requests.
  • If the SS_ERROR_LOG environment variable still works, it is clearly documented along side the above file logging and works as expected.

Notes

  • Our docs say to use Monolog\Handler\StreamHandler which we obviously don't have any control over. It's very likely that we just can't do anything about it for CMS 5 and the solution across the board is to use absolute file paths.

PRs

@GuySartorelli
Copy link
Member

GuySartorelli commented Oct 18, 2022

From the information provided in the public slack channel about this issue, the actual path for the project was not in /var/www at all - it seems like during CLI calls the path is relative to the pwd of the terminal instead of relative to the project root.

@GuySartorelli
Copy link
Member

Upgrading to impact high since the upgrade path between majors includes logging out deprecation warnings.

@emteknetnz
Copy link
Member

emteknetnz commented Mar 6, 2023

Copied from silverstripe/developer-docs#165 (comment)

app/_config/mylogging.yml

SilverStripe\Core\Injector\Injector:
  ErrorLogFileHandler:
    class: Monolog\Handler\StreamHandler
    constructor:
      - "../silverstripe.log" # an absolute path, or a path relative to the index.php file (usually inside the public/ directory)
      - "warning" # warning is the level deprecation warnings are logged as
  Psr\Log\LoggerInterface.errorhandler:
    calls:
      ErrorLogFileHandler: [ pushHandler, [ '%$ErrorLogFileHandler' ] ]

Setup

  • Requires this PR to be used / have been merged
  • Copy paste yml instructions above to app/_config/mylogging.yml
  • Construct a deprecated class in PageController::init() to trigger error
  • Call Deprecation::enable() in _config.php

When running dev/build flush=1 from CLI:

  • ./silverstripe.log will be created in root dir
  • ../silverstripe.log will say permission error, trys to create /var/www/../silverstripe.log

When requesting page via browser

  • ./silverstripe.log will be created in public dir
  • ../silverstripe.log will be created in root dir

@maxime-rainville maxime-rainville self-assigned this Mar 12, 2023
@maxime-rainville
Copy link
Contributor

We'll have a chat with our internal hosting team to make who will have more knowledge about how to handle this.

@michalkleiner
Copy link
Contributor

michalkleiner commented Mar 12, 2023

I'd say the CLI should behave like if it was run from the webroot (in terms of relative paths resolution), and then the config can stay the same and be valid for either use case.

@sabina-talipova
Copy link
Contributor

CMS 4 / CMS 5 Docs were updated. Explanations and examples were added.
CLOSED.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants