ueshin opened a new pull request, #50081:
URL: https://github.com/apache/spark/pull/50081

   ### What changes were proposed in this pull request?
   
   Fixes timestamp format for `PySparkLogger`.
   
   ### Why are the changes needed?
   
   Currently the timestamp format in JSON string from `PySparkLogger` can't be 
read by Spark with the given schema, which results in the timestamp as `NULL`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, the JSON string written by `PySparkLogger` can be read by Spark with 
the given schema.
   
   For example:
   
   ```py
   >>> import logging
   >>> from pyspark.logger import PySparkLogger, SPARK_LOG_SCHEMA
   >>>
   >>> logger = PySparkLogger.getLogger("TestLogger")
   >>> logfile = 'test_log'
   >>> handler = logging.FileHandler(logfile)
   >>> logger.addHandler(handler)
   >>> logger.setLevel(logging.INFO)
   >>>
   >>> logger.info("Test logging structure.")
   ```
   
   - before
   
   ```py
   >>> 
spark.read.format("json").schema(SPARK_LOG_SCHEMA).load(logfile).show(truncate=False)
   +----+-----+-----------------------+-------+---------+----------+
   |ts  |level|msg                    |context|exception|logger    |
   +----+-----+-----------------------+-------+---------+----------+
   |NULL|INFO |Test logging structure.|{}     |NULL     |TestLogger|
   +----+-----+-----------------------+-------+---------+----------+
   ```
   
   - after
   
   ```py
   >>> 
spark.read.format("json").schema(SPARK_LOG_SCHEMA).load(logfile).show(truncate=False)
   
+-----------------------+-----+-----------------------+-------+---------+----------+
   |ts                     |level|msg                    
|context|exception|logger    |
   
+-----------------------+-----+-----------------------+-------+---------+----------+
   |2025-02-25 16:13:18.306|INFO |Test logging structure.|{}     |NULL     
|TestLogger|
   
+-----------------------+-----+-----------------------+-------+---------+----------+
   ```
   
   ### How was this patch tested?
   
   Added the related tests.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No.
   


-- 
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: reviews-unsubscr...@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to