You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/08/04 06:25:45 UTC

[GitHub] [pulsar] tpiperatgod opened a new pull request, #16939: [feature][function] add the ability to customize logging level for Go & Python functions

tpiperatgod opened a new pull request, #16939:
URL: https://github.com/apache/pulsar/pull/16939

   Signed-off-by: laminar <[tpiperatgod@gmail.com](mailto:tpiperatgod@gmail.com)>
   
   <!--
   
   ### Contribution Checklist
   
     - PR title format should be *[[type](https://github.com/apache/pulsar/compare/master...tpiperatgod:pulsar:issue-16928?expand=1#)][component] summary*. For details, see *[[Guideline - Pulsar PR Naming Convention](https://docs.google.com/document/d/1d8Pw6ZbWk-_pCKdOmdvx9rnhPiyuxwq60_TrD68d7BA/edit#heading=h.trs9rsex3xom)](https://docs.google.com/document/d/1d8Pw6ZbWk-_pCKdOmdvx9rnhPiyuxwq60_TrD68d7BA/edit#heading=h.trs9rsex3xom)*. 
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
   
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   *(If this PR fixes a github issue, please add `Fixes #<xyz>`.)*
   
   Fixes #16928 
   
   *(or if this PR is one task of a github issue, please add `Master Issue: #<xyz>` to link to the master issue.)*
   
   Master Issue: #<xyz>
   
   ### Motivation
   
   *Currently, if the user wants to output more logging level logs other than INFO, it should provide the log settings for different pulsar function runtimes.*
   
   ### Modifications
   
   - modifications to Go functions
   
     Pass in the logging level via environment variable, such as setting `LOGGING_LEVEL`, then add parsing of the `LOGGING_LEVEL` environment variable in `log.go`, , and finally set the logging level.
   
     ```go
     const (
     	// environment variable for custom logging level
     	logLevelEnvName      = "LOGGING_LEVEL"
     	defaultLogLevel      = log.InfoLevel
     	defaultLogTimeFormat = "2006/01/02 15:04:05.000"
     )
     
     func init() {
     	log.SetLevel(defaultLogLevel)
     	// lookup and parse the logLevel variable
     	if logLevelStr, exist := os.LookupEnv(logLevelEnvName); exist {
     		if logLevel, err := log.ParseLevel(logLevelStr); err == nil {
     			log.SetLevel(logLevel)
     		}
     	}
     	log.AddHook(&contextHook{})
     	log.SetFormatter(&TextFormatter{})
     }
     ```
   
   - modifications to Python functions
   
     Add the `--logging_level` argument to `python_instance_main.py` to pass in the logging level, and add the following handle logic to `log.py` to set the logging level for each handlers.
   
     ```python
     def init_logger(level, logfile, logging_config_file):
         global Log
         # get log file location for function instance
         os.environ['LOG_FILE'] = logfile
         logging.config.fileConfig(logging_config_file)
         Log = logging.getLogger()
         # the priority of `level` is higher than `logging_config_file`
         if level != "":
             Log.setLevel(level)
             # set logging level for each handler
             for h in Log.handlers:
                 h.setLevel(level)
     ```
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
   
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API: (yes / **no**)
     - The schema: (yes / **no** / don't know)
     - The default values of configurations: (yes / **no**)
     - The wire protocol: (yes / **no**)
     - The rest endpoints: (yes / **no**)
     - The admin cli options: (yes / **no**)
     - Anything that affects deployment: (yes / **no** / don't know)
   
   ### Documentation
   
   Check the box below or label this PR directly.
   
   Need to update docs? 
   
   - [x] `doc-required` 
     (Your PR needs to update docs and you will update later)
   
   - [ ] `doc-not-needed` 
     (Please explain why)
   
   - [ ] `doc` 
     (Your PR contains doc changes)
   
   - [ ] `doc-complete`
     (Docs have been already added)
   
   [component]:


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] codelipenghui merged pull request #16939: [feature][function] add the ability to customize logging level for Go & Python functions

Posted by GitBox <gi...@apache.org>.
codelipenghui merged PR #16939:
URL: https://github.com/apache/pulsar/pull/16939


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] momo-jun commented on pull request #16939: [feature][function] add the ability to customize logging level for Go & Python functions

Posted by GitBox <gi...@apache.org>.
momo-jun commented on PR #16939:
URL: https://github.com/apache/pulsar/pull/16939#issuecomment-1208855361

   @tpiperatgod It will help users a lot if you can add the docs for this feature. Do you have any planned updates on that?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] tpiperatgod commented on pull request #16939: [feature][function] add the ability to customize logging level for Go & Python functions

Posted by GitBox <gi...@apache.org>.
tpiperatgod commented on PR #16939:
URL: https://github.com/apache/pulsar/pull/16939#issuecomment-1210080456

   > @tpiperatgod It will help users a lot if you can add the docs for this feature. Do you have any planned updates on that?
   
   I checked the changes in this PR and so far it doesn’t change the user interface, maybe I should uncheck the “doc-required” option in this PR?
   
   I will change the user-facing interface in a later PR, and I will update the documentation then.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org