LayoutDbi can contain col_types that AppenderDbi can use to create new
database tables; however, it is safer and more flexible to set up the log
table up manually with an SQL CREATE TABLE statement instead.
x <- x$new(col_types = NULL, fmt = "%L [%t] %m %f", timestamp_fmt = "%Y-%m-%d
%H:%M:%S", colors = getOption("lgr.colors", list()), pad_levels = "right")x$format_table_name(x)
x$format_colnames(x)
x$format_data(x)
x$set_col_types(x)
x$sql_create_table(table)
x$clone(deep = FALSE)
x$format_event(event)
x$set_fmt(x)
x$set_timestamp_fmt(x)
x$set_colors(x)
x$set_pad_levels(x)
x$col_names
x$col_types
x$colors
x$fmt
x$pad_levels
x$timestamp_fmt
Layouts are instantiated with <LayoutSubclass>$new(). For a description of
the arguments to this function please refer to the Fields section.
col_typesA named character vector of column types supported by
the target database. If not NULL this is used by AppenderDbi or similar
Appenders to create a new database table on instantiation of the Appender. If
the target database table already exists, col_types is not used.
col_namesConvenience method to get the names of the col_types
vector
format_table_name(x)Format table names before inserting into the database. For example some databases prefer all lowercase names, some uppercase. SQL updates should be case-agnostic, but sadly in practice not all DBI backends behave consistently in this regard
format_colnamesFormat column names before inserting into the
database. See $format_table_name for more info
format_dataFormat the input data.table before inserting into
the database. Usually this function does nothing, but for example for
SQLite it has to apply formatting to the timestamp.
col_namesConvenience method to get the names of the col_types
vector
format_event(event)format a LogEvent
Different databases have different data types and features. Currently the
following LayoutDbi subclasses exist that deal with specific databases,
but this list is expected to grow as lgr matures:
LayoutSqlite: For SQLite databases
LayoutPostgres: for Postgres databases
LayoutMySql: for MySQL databases
LayoutDb2: for DB2 databases
The utility function select_dbi_layout() tries returns the appropriate
Layout for a DBI connection, but this does not work for odbc and JDBC
connections where you have to specify the layout manually.
The LayoutDbi parameters fmt, timestamp_fmt, colors and pad_levels
are only applied for for console output via the $show() method and do not
influence database inserts in any way. The inserts are pre-processed by
the methods $format_data(), $format_colnames and $format_tablenames.
It does not format
LogEvents directly, but their data.table representations (see
as.data.table.LogEvent), as well as column- and table names.
select_dbi_layout(), DBI::DBI,
Other Layouts: LayoutFormat,
LayoutGlue, LayoutJson,
Layout