Service: Logflare - EyevinnOSC/community GitHub Wiki
Logflare is a log ingestion and querying engine that allows the storage and querying of log events in a columnar database. Available as an open web service in Eyevinn Open Source Cloud to get you up and running in minutes. This tutorial guides you through the steps to get started.
- If you have not already done so, sign up for an Eyevinn OSC account
To store the log events we will first create a PostgreSQL database. To create a PostgreSQL database navigate to the PostgreSQL service in the Eyevinn OSC web console. Click on the button "Create psql-db" and enter a name of the instance and a password.
Important when creating the database is to initiate it with the SQL ALTER SYSTEM SET wal_level = 'logical';
as this cannot be configured once the database instance is up and running.
Based on the IP and port the URI to your PostgreSQL database is postgres://postgres:logflare@<IP>:<PORT>/postgres
.
In our example it is postgres://postgres:[email protected]:10528/postgres
.
It is a good practice to store the database credentials as a secret and refer to it when creating an instance. Before we setup a Logflare instance we will create a secret where we will store the URI with credentials to the database. Navigate to the Logflare service in Eyevinn Open Source Cloud web console. Go to the tab "Service Secrets" and click on "New Secret".
In our example it was postgres://postgres:[email protected]:10528/postgres
and we will store it in the a secret named dburl
.
Now we can create the Logflare instance by going to the tab "My logflares" and click on "Create logflare".
We refer to the created secret in step 2 for the database connection string.
Click on the instance card when the status is green and "running".
Now we can create a source where we can log events. Click on the button "New source" and give it a name, for example myapp
.
Note down the Source ID and the generated API key. In our example the id is bf5cef0e-ecd2-4179-8426-2fcaae95467e
and the API key is GkPU299GZL1E
.
As an example we will develop a NodeJS application to send the logs. First initiate a project.
% mkdir myapp
% cd myapp
% npm init
Then install the pino and pino-logflare library.
% npm install --save pino pino-logflare
Create a file called myapp.js
and insert the following code where the apiKey
is in our case GkPU299GZL1E
and the sourceToken
is the Source ID bf5cef0e-ecd2-4179-8426-2fcaae95467e
. The apiBaseUrl
is the URL on the instance card, in our case https://eyevinnlab-guide.logflare-logflare.auto.prod.osaas.io
.
import pino from "pino"
import { createWriteStream } from "pino-logflare"
const stream = createWriteStream({
apiKey: "GkPU299GZL1E",
apiBaseUrl: "https://eyevinnlab-guide.logflare-logflare.auto.prod.osaas.io",
sourceToken: "bf5cef0e-ecd2-4179-8426-2fcaae95467e",
});
// create pino loggger
const logger = pino(
{},
stream
)
// log some events
logger.info("Informational message")
logger.error(new Error("things got bad"), "error message")
const child = logger.child({ property: "value" })
child.info("hello child!")
Now let us run this code.
% node myapp.js
And if we then go back to the Logflare console we would see this.