Thanks @yosiasz
Based on your input and Winston-loki not working with Grafana Cloud Loki · Issue #108 · JaniAnttonen/winston-loki · GitHub I created this simple code. 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.