@logmint/sdk
v1.1.6
Published
LogMint SDK for sending audit logs, metrics, application logs
Downloads
229
Maintainers
Readme
Hey there!
Welcome to LogMint SDK
Watch full demo here
Visit site
This SDK will help you log events directly on our cloud or in your local database just with the help of a few lines of code.
Local Setup
Install package using
npm install @logmint/sdkFor local setup, just initailize and connect to your database:
const { init, log } = require("@logmint/sdk");
const { Pool } = require("pg");
await init({
db: {
client: new Pool({
host: "localhost",
user: "postgres",
password: "admin",
port: 5432,
database: "todo",
}),
},
mode: "local",
});The SDK will automatically create an events table if it does not exist in your database. If you want to manually create it, use the query:
CREATE TABLE IF NOT EXISTS events (
id SERIAL PRIMARY KEY,
event_type TEXT NOT NULL,
actor_id TEXT NOT NULL,
actor_name TEXT NOT NULL,
resource_id TEXT NOT NULL,
resource_type TEXT NOT NULL,
ip_address TEXT,
user_agent TEXT,
metadata JSONB,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Log events
await log({
event_type: "user.paid.first.order",
actor_name: "shreya",
actor_id: "1",
resource_id: "#1",
resource_type: "mobile app",
metadata: { old_column: "old", new_column: "new" },
});You can visualize the audit logs on the site:
Cloud Setup
- Install package using
npm install @logmint/sdk
const { init, log, flush, addMetric } = require("@logmint/sdk");
await init({
mode: "cloud",
apiKey: "YOUR_API_KEY",
secretKey: "YOUR_SECRET_KEY",
url: "https://api.getlogmint.com"
});Log events
await log({
event_type: "user.paid.first.order",
actor_name: "shreya",
actor_id: "1",
resource_id: "#1",
resource_type: "mobile app",
metadata: { old_column: "old", new_column: "new" },
});If events fail to get logged, it will automatically get pushed to redis. You'll have to flush it out.(Recommended once a week).
const { flush } = require("@logmint/sdk");
await flush();Add metrics
await addMetric({
name:"user.signup",
value:1,
type:"counter",
tags:{env:"prod"}
})Once you have added the metrics, you can visualize them on the app and even create widgets:
Application logs
Application logs are automatically captured!
