Comments (3)
@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.
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.
I really appreciate your snippet. In my case my host was wrong. Thank you
from winston-loki.
Related Issues (20)
- I cannot start project HOT 1
- use Symbol.for('level') when extracting label HOT 1
- useCustomFormat is broken
- Race condition in batching leading to lost logs HOT 1
- QUESTION: How many log levels are supported? HOT 2
- Feature Request: awaitable finishRequests method
- TypeError: winston_loki_1.default is not a constructor HOT 2
- Remote Loki HOT 1
- Possible to quit the batcher loop ASAP when closing? HOT 1
- [patch] A method to wait until all the logs are physically sent to winston HOT 3
- Docs: Add a section to explain how to make it work with nextjs and/or webpack HOT 5
- Snappy optionalDependency upgrade breaks build HOT 2
- CVE-2023-36665 protobufjs Dependency HOT 3
- Childlogger with additional labels
- NodeJS crash when batching is enabled
- Segmentation fault with swc & vitest in github action ubuntu-latest when using version 6.0.7
- Documentation improvement ideas
- logfmt syntax error with Grafana cloud
- push log to grafana cloud having logs lost
- Module parse failed error on Next.js 14 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from winston-loki.