Class LogConnector
java.lang.Object
com.darkcollective.relix.connectors.std.internal.LogConnector
- All Implemented Interfaces:
RelixConnector,AutoCloseable
Reads a web server's access log as a relation:
connection X from log { … }.
connection logs from log { path: "/var/log/nginx", format: "combined" };
source Access from logs { table: "access.log",
schema: { host: STRING, at: TIMESTAMP, method: STRING, path: STRING,
status: NUMBER, bytes: NUMBER, referer: STRING, agent: STRING } };
The format decides the fields, and their types
format is common, combined, or the server's own format string,
pasted from its configuration: Apache's LogFormat or nginx's
log_format; it defaults to common, and clf is another name for
the log type. What a log is worth to a query is the typing: the request time
is a TIMESTAMP, the status
and byte count are numbers, the request line is split into method,
path and protocol, and a - is NULL wherever it appears.
The declared schema decides the heading
Every column is filled by name, and a column the format does not produce is NULL, the rule the GEDCOM connector follows. A dotted reference, with nothing declared, gets every field the format produces.A directory holds several logs
When the connection's file is a directory,table names a file in it, so
access.log and a rotated access.log.2.gz are two tables of one
connection. When it is a file, table names that file. A gzip file is read
transparently.
Reading
A log is streamed a line at a time rather than read whole, so the relation holds an open file until the query closes it. A line the format does not match is an error naming its line number, unless the connection saysonError: "skip": then it
is left out, and the number skipped is logged when the file is closed. Blank lines
are not records and are passed over.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionhandles()The type tokens this connector handles, lower-cased — e.g.open(ConnectorConfig config, String table, Schema schema) Opens a stream of rows for a named table/collection/endpoint.tableSchema(ConnectorConfig config, String table) Introspects the schema of a table, when the backend supports it.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.darkcollective.relix.processor.connector.RelixConnector
close, openQuery, tableStatistics
-
Constructor Details
-
LogConnector
public LogConnector()Public no-arg constructor required forServiceLoaderdiscovery.
-
-
Method Details
-
handles
Description copied from interface:RelixConnectorThe type tokens this connector handles, lower-cased — e.g.{"jdbc"},{"csv"},{"mongodb"}. The registry uses these for dispatch.- Specified by:
handlesin interfaceRelixConnector- Returns:
- a non-empty set of handled type tokens
-
tableSchema
Introspects the schema of a table, when the backend supports it. The default returns empty — "not available", in which case the declared schema is used as-is.Every field the format produces, at its natural type. Described from the format alone, so an unreadable file does not stop analysis.
- Specified by:
tableSchemain interfaceRelixConnector- Parameters:
config- the connector configurationtable- the table/collection name- Returns:
- the introspected schema, or empty when unavailable
-
open
Description copied from interface:RelixConnectorOpens a stream of rows for a named table/collection/endpoint. The caller closes the returned stream.- Specified by:
openin interfaceRelixConnector- Parameters:
config- the connector configuration for this relationtable- the table/collection/endpoint name within the sourceschema- the expected output schema (column order and types)- Returns:
- a stream of rows; the caller is responsible for closing it
-