question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Console.log calls result in multiple log entries where a single entry is expected

See original GitHub issue

Console.log calls that end up with newlines in them cause multiple log entries rather than single (collapsed) log entries. Logging a string with newlines causes this, as does logging a “large enough” object (which seems to get stringified differently to a “small enough” object to get newlines in its output).

I also note that the log type field is ? rather than I as is was under node 8.

The log outputs below were produced by just changing between "engines": { "node": "8" } and "engines": { "node": "10" }, and deploying, with no other changes.

Related issues

none

Version info

node:

v10.15.3

firebase-functions:

3.3.0

firebase-tools:

7.12.1

firebase-admin:

8.9.0

Test case

exports.test = functions.https.onRequest((req, res) => {
	console.log('multiple lines', 'line one\nline two\nline three')
	console.log('small object', { one: 'one', two: 'two', three: 'three' })
	console.log('object', { one: 'one', two: 'two', three: 'three', four: 'four', five: 'five', six: 'six' })
	res.send({})
})

Steps to reproduce

deploy test function call test function view log

Expected behaviour

single log entries (as per node8 version)

2020-01-20T00:31:29.897645002Z D test: Function execution started
2020-01-20T00:31:29.907Z I test: multiple lines line one
line two
line three
2020-01-20T00:31:30.004Z I test: small object { one: 'one', two: 'two', three: 'three' }
2020-01-20T00:31:30.005Z I test: object { one: 'one',
  two: 'two',
  three: 'three',
  four: 'four',
  five: 'five',
  six: 'six' }
2020-01-20T00:31:30.006307295Z D test: Function execution took 109 ms, finished with status code: 200

Actual behavior

multiple log entries for “large enough” objects, or any string with newlines

2020-01-20T00:29:01.446537764Z D test: Function execution started
2020-01-20T00:29:01.791Z ? test: multiple lines line one
2020-01-20T00:29:01.792Z ? test: line two
2020-01-20T00:29:01.792Z ? test: line three
2020-01-20T00:29:01.795Z ? test: small object { one: 'one', two: 'two', three: 'three' }
2020-01-20T00:29:01.795Z ? test: object { one: 'one',
2020-01-20T00:29:01.795Z ? test:   two: 'two',
2020-01-20T00:29:01.795Z ? test:   three: 'three',
2020-01-20T00:29:01.795Z ? test:   four: 'four',
2020-01-20T00:29:01.795Z ? test:   five: 'five',
2020-01-20T00:29:01.795Z ? test:   six: 'six' }
2020-01-20T00:29:01.802375869Z D test: Function execution took 356 ms, finished with status code: 200

Were you able to successfully deploy your functions?

yes, no errors

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:67
  • Comments:40 (13 by maintainers)

github_iconTop GitHub Comments

15reactions
mbleighcommented, Jun 19, 2020

If you put

require('firebase-functions/lib/logger/compat');

at the top of your functions code with the latest version of the sdk logging should work as it did before in node 10. You can also use the new logging SDK to take advantage of structured logging support

On Fri, Jun 19, 2020, 6:53 AM Ashemah Harrison notifications@github.com wrote:

So we now need to spend additional time and money upgrading all of our apps just so logging is back to where it was before? What kind of weird logic is this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-functions/issues/612#issuecomment-646649336, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAH7TGWZITNAH4KWUB5FDRXNUXBANCNFSM4KI4WPVQ .

10reactions
mbleighcommented, May 22, 2020

We are working on a new logging SDK for Cloud Functions for Firebase that will support richer logging and proper multiline logs. Stay tuned!

On Thu, May 21, 2020, 5:47 PM David Clark notifications@github.com wrote:

Hello, apologies for commenting on a closed issue, but with the email today stating “Developers will no longer be able to create new functions or update existing functions that use Node.js 8.” from February 15, 2021 - I thought I would check back and see what had happened.

@mbleigh https://github.com/mbleigh Do you have any update for us? Is there anywhere else I can go to track this issue and get info on what is being done? We REALLY want to go to node 10 but all of our logging has newlines in it (an object through JSON.stringify can cause that for example). Indeed, we are already running into issues where libs that we are using have (quite rightly) removed support for node 8.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-functions/issues/612#issuecomment-632417966, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAH7RWFSDTOI3R5UVEFPLRSXDRBANCNFSM4KI4WPVQ .

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use console.log(); for multiple variables - Stack Overflow
Using p5.js, I am trying to log two different variables to the console, and I am only able to log one of the...
Read more >
5 Ways to Log an Object to the Console in JavaScript
If you are like me, you've run into the issue of trying to log a JavaScript ... The result of Object.entries(object) and console.log()....
Read more >
LogEntry | Cloud Logging
Information indicating this LogEntry is part of a sequence of multiple log entries split from a single LogEntry. Union field payload . The...
Read more >
console.log() - Web APIs - MDN Web Docs
The console.log() method outputs a message to the web console. The message may be a single string (with optional substitution values), ...
Read more >
Write and view logs | Cloud Functions for Firebase - Google
You have an existing code base and prefer not to refactor from console.log . You're familiar with Cloud Logging (formerly StackDriver logging) and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found