Giter Site home page Giter Site logo

Comments (3)

MatthewPattell avatar MatthewPattell commented on June 2, 2024 9

@danmdinu try this:

logger.add(new LokiTransport({
  host: 'https://logs-prod-eu-west-0.grafana.net',
  json: true,
  basicAuth: '123456:.....',
  labels: { job: 'winston-loki-example' },
  replaceTimestamp: true,
}))

I tested it for Grafana & Loki in the Cloud.

from winston-loki.

terchris avatar terchris commented on June 2, 2024 7

I had some problems getting this working. I think that my problem was that I had my parameters wrong (URL and probably password). There are probably return codes that can be inspected to help in case it does not work.
I was looking for a simple code to test- I could not find one so I created it.

/* The siplest test ever to see if grafana cloud and winston is working 
A small node app that sends a log message to Grafana Cloud Loki using the winston-loki transport.
To you by terchris and friends.
*/
import winston from "winston";
import LokiTransport from "winston-loki"

// https://grafana.com/orgs/urbalurba (change urbalurba to your own org)
// in the Loki card. Click on the Details button. On the next page you will se the Grafana Data Source settings.
// Create a password  and replace the const variables below with your own values. 
const GRAFANA_HOST = "https://logs-prod-eu-west-0.grafana.net";
const MY_APP_NAME = "urbalurba";

const GRAFANA_USERID = "333666";
const GRAFANA_PASSWORD = "eyJr1234567890FjYzZlOTg2NTE5ZDIyY12345678900ODdlZjAx1234567890IsIm4iOiJ1234567890iwi1234567890cyM30=";

// start leave this as is
const GRAFANA_BASICAUTH = GRAFANA_USERID + ":" + GRAFANA_PASSWORD;
const logger = winston.createLogger({

    level: 'debug',
      
    transports: [
      new LokiTransport({
        host: GRAFANA_HOST,
          labels: { app: MY_APP_NAME },
          json: true,
          basicAuth: GRAFANA_BASICAUTH,
          format: winston.format.json(),
          replaceTimestamp: true,
          onConnectionError: (err) => console.error(err)
        }),
      new winston.transports.Console({}),      
    ],
  });
// end leave this as is  

// send some log messages
logger.info("Starting test");
logger.debug("sending debug message");
logger.warn("sending warn message");
logger.error("sending error message");
logger.info("done testing");

// To see the logging in grafana cloud, go to Explore https://urbalurba.grafana.net/explore (change urbalurba to your own org)
// At the top there is a dropdown. Select the one with the Loki logo (in my case grafanacloud-urbalurba-logs) 
// In the "Select label" dropdown select "app" and in the "Select value" dropdown select "urbalurba" (change urbalurba to your own app name)
// Click on the "Run Query" button in the upper right corner. You should see the log messages you sent above.

from winston-loki.

lesimoes avatar lesimoes commented on June 2, 2024

I really appreciate your snippet. In my case my host was wrong. Thank you

from winston-loki.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.