SDKs overview
Logs.to provides Software Development Kits (SDKs) and client libraries to enable developers to integrate log collection directly into their applications. These SDKs are designed to streamline the process of sending structured log data to the Logs.to platform, supporting real-time log ingestion, search, and analysis. The availability of official SDKs for multiple programming languages aims to offer a consistent and developer-friendly experience across different tech stacks.
The primary function of these SDKs is to abstract the underlying HTTP API interactions, allowing developers to focus on logging relevant application events rather than managing API requests, authentication, or error handling. Logs.to emphasizes structured logging, which involves sending log data as JSON objects with key-value pairs, making it easier to query and analyze logs programmatically. This approach aligns with modern observability practices, where logs are treated as machine-readable data rather than plain text strings. For more details on structured logging benefits, refer to the Google Cloud structured logging guide.
Beyond the official SDKs, Logs.to also supports standard logging agents like Fluent Bit and direct HTTP API ingestion, offering flexibility for environments where a dedicated SDK might not be suitable or preferred. The official documentation provides comprehensive guides for each integration method, ensuring developers can choose the most appropriate solution for their specific application architecture and logging requirements.
Official SDKs by language
Logs.to offers official SDKs for several programming languages, each designed to provide idiomatic interfaces for log ingestion. These SDKs are maintained by Logs.to and are the recommended method for integrating applications with the platform. They handle details such as API endpoint configuration, payload formatting, and secure communication.
The following table lists the currently available official SDKs:
| Language | Package/Module Name | Primary Installation Method | Maturity Level |
|---|---|---|---|
| Go | logs.to/go-sdk |
go get logs.to/go-sdk |
Stable |
| JavaScript (Node.js/Browser) | @logs.to/js-sdk |
npm install @logs.to/js-sdk or yarn add @logs.to/js-sdk |
Stable |
| Rust | logs_to |
Add to Cargo.toml: logs_to = "0.1.0" |
Stable |
| Python | logs-to |
pip install logs-to |
Stable |
Each SDK provides functions and classes to initialize a client, configure logging levels, and send structured log entries. The design of these SDKs aims for minimal overhead and easy configuration, allowing developers to quickly integrate log sending capabilities into new or existing projects. Further details on each SDK's specific features and configuration options can be found in the Logs.to official documentation.
Installation
Installing the Logs.to SDKs typically follows the standard package management practices for each respective language. Below are the common installation steps for the official SDKs:
Go
To install the Go SDK, use the go get command:
go get logs.to/go-sdk
After installation, you can import the package into your Go application:
import "logs.to/go-sdk"
JavaScript (Node.js/Browser)
For JavaScript environments, the SDK is available via npm or yarn:
npm install @logs.to/js-sdk
# or
yarn add @logs.to/js-sdk
You can then import it into your Node.js or browser application:
// CommonJS
const logsTo = require('@logs.to/js-sdk');
// ES Modules
import logsTo from '@logs.to/js-sdk';
Rust
To use the Rust SDK, add it as a dependency in your Cargo.toml file:
[dependencies]
logs_to = "0.1.0"
Then, run cargo build or cargo run, and Cargo will fetch and compile the dependency. You can then use it in your Rust code:
use logs_to::Logger;
Python
Install the Python SDK using pip:
pip install logs-to
After installation, you can import the library into your Python script:
import logs_to
Each installation method ensures that the necessary dependencies are resolved and the SDK is ready for use within your development environment. Comprehensive installation guides are available on the Logs.to documentation portal.
Quickstart example
This section provides a basic quickstart example for each official SDK, demonstrating how to initialize the client and send a simple structured log entry. These examples assume you have already installed the respective SDK and have a Logs.to API key available.
Go Quickstart
Initialize the Go client and send a log message:
package main
import (
"context"
"fmt"
"os"
logsto "logs.to/go-sdk"
)
func main() {
// Replace with your actual Logs.to API key
apiKey := os.Getenv("LOGS_TO_API_KEY")
if apiKey == "" {
fmt.Println("LOGS_TO_API_KEY environment variable not set.")
return
}
logger := logsto.NewLogger(apiKey)
// Send a structured log entry
err := logger.Log(context.Background(), map[string]interface{}{
"message": "User logged in successfully",
"user_id": 123,
"event_type": "auth",
"level": "info",
})
if err != nil {
fmt.Printf("Failed to send log: %v\n", err)
return
}
fmt.Println("Log sent successfully to Logs.to")
}
JavaScript Quickstart (Node.js)
Initialize the JavaScript client and send a log message:
import LogsTo from '@logs.to/js-sdk';
const apiKey = process.env.LOGS_TO_API_KEY;
if (!apiKey) {
console.error('LOGS_TO_API_KEY environment variable not set.');
process.exit(1);
}
const logger = new LogsTo(apiKey);
async function sendLog() {
try {
await logger.log({
message: 'Processing user data',
user_id: 456,
service: 'data-processor',
level: 'debug'
});
console.log('Log sent successfully to Logs.to');
} catch (error) {
console.error('Failed to send log:', error);
}
}
sendLog();
Rust Quickstart
Initialize the Rust client and send a log message:
use logs_to::{Logger, LogEntry};
use std::collections::HashMap;
use std::env;
#[tokio::main] // Requires the 'tokio' feature if using async
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = env::var("LOGS_TO_API_KEY")
.map_err(|_| "LOGS_TO_API_KEY environment variable not set.")?;
let logger = Logger::new(&api_key);
let mut entry = HashMap::new();
entry.insert("message".to_string(), serde_json::Value::String("Application started".to_string()));
entry.insert("component".to_string(), serde_json::Value::String("startup".to_string()));
entry.insert("version".to_string(), serde_json::Value::String("1.0.0".to_string()));
logger.log(LogEntry::new(entry)).await?;
println!("Log sent successfully to Logs.to");
Ok(())
}
Python Quickstart
Initialize the Python client and send a log message:
import os
from logs_to import LogsTo
api_key = os.getenv("LOGS_TO_API_KEY")
if not api_key:
print("LOGS_TO_API_KEY environment variable not set.")
exit(1)
logger = LogsTo(api_key)
def send_log():
try:
logger.log({
"message": "Database connection established",
"database": "production_db",
"status": "connected",
"level": "info"
})
print("Log sent successfully to Logs.to")
except Exception as e:
print(f"Failed to send log: {e}")
send_log()
These quickstart examples provide a basic demonstration. For advanced configurations, error handling, batching, and asynchronous logging, consult the Logs.to comprehensive documentation.
Community libraries
While Logs.to provides official SDKs, the open nature of logging and API interactions often leads to community-contributed libraries and integrations. These community projects can offer alternative implementations, integrations with specific frameworks, or utilities that complement the official SDKs.
Community libraries are typically developed and maintained independently by developers within the Logs.to user base. Their features, stability, and support can vary. Before adopting a community library, it is advisable to review its source code, check its activity on platforms like GitHub, and assess its alignment with your project's requirements and maintenance capabilities. Resources for discovering community projects often include:
- GitHub: Searching for
logs.to clientor similar terms. - Package Registries: Checking language-specific registries (e.g., npm, PyPI, Crates.io) for packages mentioning Logs.to.
- Community Forums/Discussions: Engaging with other Logs.to users to learn about their preferred tools.
Logs.to encourages community contributions and often highlights well-maintained or widely used third-party integrations in its documentation or community channels. However, support for these libraries typically comes from their respective maintainers rather than directly from Logs.to. For official support and guaranteed compatibility, the Logs.to official SDKs are the recommended choice.
An example of such a community contribution might be a logging adapter for a web framework (e.g., a Flask extension for Python or an Express middleware for Node.js) that automatically captures request details and sends them to Logs.to. These can simplify integration for specific application types, building on top of the core SDK functionality to provide higher-level abstractions. Developers often leverage existing logging frameworks like Python's logging module or Rust's tracing crate, and community libraries might provide a Logs.to backend for these widely-used systems. For an overview of common logging patterns in different languages, the MDN Web Docs on Console logging illustrate basic practices.