I'm running a cloud function every minute.
Blank lines (see logs below) appear in Stackdriver logs intermittently.
I don't believe this is due to the function code I have written.
Bug can be recreated with this main.py:
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.info(f"Logging {__name__}")
def main(event, context):
    logger.info("Message 1")
    logger.info("Message 2")
    logger.info("Message 3")
This function emitted blanks lines within a couple hours when triggered every minute by Cloud Scheduler.
How can this issue be prevented?
Update: Added two expanded logs
{
 insertId: "000001-redacted-but-identical"  
 labels: {
  execution_id: "894004659398898"   
 }
 logName: "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions"  
 receiveTimestamp: "2019-12-13T23:05:01.545007423Z"  
 resource: {
  labels: {
   function_name: "recreate_blank_lines"    
   project_id: "redacted"    
   region: "us-central1"    
  }
  type: "cloud_function"   
 }
 severity: "INFO"  
 timestamp: "2019-12-13T23:05:00.344Z"  
 trace: "projects/redacted/traces/c4ed0267fd9fa4bf9133043bdfe5b1e0"  
}
{
 insertId: "000000-redacted-but-identical"  
 labels: {
  execution_id: "894004659398898"   
 }
 logName: "projects/redacted/logs/cloudfunctions.googleapis.com%2Fcloud-functions"  
 receiveTimestamp: "2019-12-13T23:05:01.545007423Z"  
 resource: {
  labels: {
   function_name: "recreate_blank_lines"    
   project_id: "redacted"    
   region: "us-central1"    
  }
  type: "cloud_function"   
 }
 severity: "INFO"  
 textPayload: "Message 2"  
 timestamp: "2019-12-13T23:05:00.345Z"  
 trace: "projects/redacted/traces/c4ed0267fd9fa4bf9133043bdfe5b1e0" 


In the meantime, you can add a filter to stackdriver to skip logs with empty strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With