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

[Feature Enhancement] - v10.x - Support logging to file #341

Open
judimator opened this issue Sep 27, 2023 · 3 comments
Open

[Feature Enhancement] - v10.x - Support logging to file #341

judimator opened this issue Sep 27, 2023 · 3 comments
Labels
good first issue Indicates a good issue for first-time contributors

Comments

@judimator
Copy link

Hi there,

During my work I found the following issue

Env:

  • pact-php: 10.0.0-alpha2
  • phpunit: 10.3.4

Step to reproduce:

  • Set PACT_LOG var (for example ./log/pact.log)
  • Run a test

Expected result:
The file exists

Actual result:
The file not found

@tienvx
Copy link
Contributor

tienvx commented Sep 27, 2023

Hi @judimator , thanks for reporting the issue.

After a quick look at pact-reference and pact-php (version 10 alpha) projects, I think:

  • Currently only PACT_LOGLEVEL is supported
  • PACT_LOG is the code leftover from version 9, and it does not do anything, and should be removed
  • This code can provide similar behavior, but I didn't implement it yet. I think we can find a way to use it in the future alpha version

cc @YOU54F Thanks for the useful code . Do you know how pact's implementation in other languages handle this one?

@YOU54F
Copy link
Member

YOU54F commented Sep 27, 2023

Hey,

Pact-JS doesn't support logging to file at the moment ( I made a draft PR here pact-foundation/pact-js-core#428)

The current interface between the ffi for init'ing with the logger is here

https://github.com/pact-foundation/pact-js-core/blob/master/native/ffi.cc#L12

There are some convenience functions to setup a logger

https://docs.rs/pact_ffi/latest/pact_ffi/log/index.html

I believe these call logger_apply, where as calling pactffi_logger_attach_sink allows you to setup multiple loggers, prior to calling pactffi_logger_apply

I did notice that once you've called pactffi_logger_apply you can't change the logger settings within the same process, so you change the log level or mode for a particular test (it caused me issues when trying to test pact-python with the ffi, where there were unit tests that tested log levels)

Further examples

@YOU54F
Copy link
Member

YOU54F commented Sep 27, 2023

in my pr for pact python i tried this out to set the log level at init time, depending on the env vars presented by the user

https://github.com/pact-foundation/pact-python/pull/367/files#diff-c666652e61742bd29834872c24326ac8e8ff8be3ed3d645fe596968ed9013938R66

instructions

https://github.com/pact-foundation/pact-python/pull/367/files#diff-b059f16e86de3ca400fc1d0b7a623bb0aa703cd3357d45dc0cc931b7f3f0a3e3R148

so it can easily be controlled externally to dump to a file, buffer etc or set a log level. that code shown only sets up one logger sink though, so if your code relies on pulling anything back from a log buffer and it’s instead been setup with a file or stdout, the data won’t be present.

it will probably be implemented differently in the end but might be worth sharing :)

@YOU54F YOU54F added the good first issue Indicates a good issue for first-time contributors label May 16, 2024
@YOU54F YOU54F changed the title There is no any log file while running a test [Feature Enhancement] - v10.x - Support logging to file May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indicates a good issue for first-time contributors
Projects
Status: New Issue
Development

No branches or pull requests

3 participants