4

I am using npm @google-cloud/logging-winston to send application log events to google stack-driver log sinks. Below is my code snippet and it works perfectly fine in my local macbook. When i try to run it inside a GCE instance (ubuntu 16.10 image compute instance on google cloud),it does not send the log events to log sinks and i am not able to see it on google cloud logging dashboard. Any help here appreciated

        ///// code start here
            const winston = require('winston');
        const Logger = winston.Logger;
        const Console = winston.transports.Console;

        const LoggingWinston = require('@google-cloud/logging-winston');

        // Instantiates a Winston Stackdriver Logging client
        const loggingWinston = LoggingWinston({
        projectId: 'myproject-id',
        keyFilename: 'mykey.json',
        level: 'info',// log at 'warn' and above ,


        labels: { "env": "poc" }
        ,
        logName: "poc-gcl.log"
        });

        // Create a Winston logger that streams to Stackdriver Logging
        // Logs will be written to: "projects/YOUR_PROJECT_ID/logs/winston_log"
        const logger = new Logger({
        level: 'info', // log at 'info' and above
        transports: [
            // Log to the console
            new Console(),
            // And log to Stackdriver Logging
            loggingWinston
        ]



        });

        // Writes some log entries
        logger.info('Node Winston logger initialized.Transport GCL Stakdriver logging', 
        { type: "poc", server: "test" });


        //code ends here.

thanks in advance - jag

Jag shetty
  • 41
  • 2
  • It does look like you already went through [this](https://cloud.google.com/logging/docs/setup/nodejs#using_winston) tutorial. But just to confirm, [here](https://cloud.google.com/logging/docs/setup/nodejs#using_winston) is our documentation to setup Winston. In the event you already went through the documentation and it's still giving you errors, I would suggest opening a defect report in [issue tracker](https://cloud.google.com/support/docs/issue-trackers) with the errors(if any) you are getting. – Digil Jan 19 '18 at 04:29
  • Did you ever find the issue? For me - works no problem locally. On the GCE instance (Kubernetes engine) there are no errors but the logs aren't appearing in Logging (Global logs). cloud-platform (all api's) scope applied to instances. Service account has log writer (tried log admin) @Digil – Stan Bondi Feb 14 '18 at 19:15
  • 1
    For the life of me, I cannot find these log entries at all when executing the sample code from my desktop or from the Cloud Shell examples. They just disappear! I hope I'm looking in the right place, but I've looked everywhere in the GCP console logs, all resources and all log types. So frustrating! – BK- Mar 09 '18 at 23:52

2 Answers2

4

Had the same issue, in the end it was because I was looking at the wrong place:

  • When logging from outside Google Cloud Platform (such as your computer), if you haven't provided a resource to log against, the library routes logs to the 'Global' resource by default.

  • When doing the same from inside Google Cloud Platform, logs can be found in 'GCE VM Instance' category.

joseluissb
  • 61
  • 4
  • Using Cloud Run also logs to the 'Global' resource. – seeARMS Sep 12 '19 at 01:19
  • Hi can you be a bit more specific about how to fix this? For me, when running locally, it hangs there for 2 mins and throw an error (from the log writing api). – Tri Nguyen Jul 22 '20 at 13:58
1

Perhaps not the answer, but it may help. I had issue sending local logs to Stackdriver as well and finally realized that my service account didn't have the right permissions. Specifically "Logs Writer" role.

https://cloud.google.com/iam/docs/granting-roles-to-service-accounts#granting_access_to_a_service_account_for_a_resource

BK-
  • 527
  • 7
  • 19