Class IntradayLoggerBuilder<LOGGER_TYPE extends com.illumon.intradaylogger.IntradayLogger>

java.lang.Object
com.illumon.iris.db.util.logging.IntradayLoggerBuilder<LOGGER_TYPE>

public class IntradayLoggerBuilder<LOGGER_TYPE extends com.illumon.intradaylogger.IntradayLogger> extends Object
Builder to create and initialize IntradayLogger instances, with static helpers for some specific logger types.

In all cases, this factory will determine the internal partition (or a prefix thereof, if log-format suffixing is set) through getInternalPartitionForLogs(IntradayLogger, String).

If binary log files are being written directly (the LAS is not used), the process name will be prefixed to the internal partition name to help distinguish them.

  • Field Details

  • Constructor Details

    • IntradayLoggerBuilder

      public IntradayLoggerBuilder(@NotNull Class<LOGGER_TYPE> loggerClass)
      Construct a builder for new IntradayLoggers.
      Parameters:
      loggerClass - The IntradayLogger Class to be instantiated
  • Method Details

    • setProcessName

      public IntradayLoggerBuilder<LOGGER_TYPE> setProcessName(@NotNull String processName)
      Set property prefix to be used for log creation and initialization. Required.
      Parameters:
      processName - Property prefix to be used for log creation and initialization
      Returns:
      This builder.
    • setNamespaceSet

      public IntradayLoggerBuilder<LOGGER_TYPE> setNamespaceSet(@NotNull TableIdentifier.NamespaceSet namespaceSet)
      Set the TableIdentifier.NamespaceSet (USER or SYSTEM) for the logger. Defaults to TableIdentifier.NamespaceSet.SYSTEM Required.
      Parameters:
      namespaceSet - The TableIdentifier.NamespaceSet for the logger
      Returns:
      This builder.
    • setNamespace

      public IntradayLoggerBuilder<LOGGER_TYPE> setNamespace(@Nullable String namespace)
      Set the namespace for the new logger if the logger's default should not be used. Optional.
      Parameters:
      namespace - The namespace for the new logger
      Returns:
      This builder.
    • setTableName

      public IntradayLoggerBuilder<LOGGER_TYPE> setTableName(@Nullable String tableName)
      Set the table name for the new logger, if the logger's default should not be used. Optional.
      Parameters:
      tableName - The table name for the new logger
      Returns:
      This builder.
    • setTimeZoneName

      public IntradayLoggerBuilder<LOGGER_TYPE> setTimeZoneName(@Nullable String timeZoneName)
      Set the name of the time zone to be used to determine column partition values and file name date-time stamps. Optional.

      If none is provided the system default will be used.

      This is ignored for non-dynamic loggers using the log aggregator service.

      Superceded when a column partition function or a column partition value is set and used.

      Parameters:
      timeZoneName - The time zone name
      Returns:
      This builder.
    • setColumnPartitionFunction

      public IntradayLoggerBuilder<LOGGER_TYPE> setColumnPartitionFunction(@Nullable Function<?,String> columnPartitionFunction)
      Set a function to be used to compute the column partition value for function-based column partition determination. Optional.

      Superceded when a column partition value is set and used.

      Parameters:
      columnPartitionFunction - The column partition function
      Returns:
      This builder.
    • setColumnPartitionValue

      public IntradayLoggerBuilder<LOGGER_TYPE> setColumnPartitionValue(@Nullable String columnPartitionValue)
      Set the column partition value to be used. Optional.
      Parameters:
      columnPartitionValue - The column partition value
      Returns:
      This builder.
    • setForceUseLas

      public IntradayLoggerBuilder<LOGGER_TYPE> setForceUseLas(boolean forceUseLas)
      Set whether to always use the log aggregator service (LAS). Defaults to false. Optional.
      Parameters:
      forceUseLas - Whether to force use of the log aggregator service (LAS)
      Returns:
      This builder.
    • setStandalone

      public IntradayLoggerBuilder<LOGGER_TYPE> setStandalone(boolean standalone)
      Set whether to skip logger checksum verification, appropriate for logging processes that cannot contact a remote schema service. Defaults to false. Optional.
      Parameters:
      standalone - Whether to skip logger checksum verification
      Returns:
      This builder.
    • setSuffixInternalPartitionWithLogFormat

      public IntradayLoggerBuilder<LOGGER_TYPE> setSuffixInternalPartitionWithLogFormat(boolean suffixInternalPartitionWithLogFormat)
      Set whether to suffix internal partitions with the log format. Defaults to false. Optional.

      Example: If the internal partition would normally have been "ABC" and the logger format is version 4, the actual partition used would be: "ABC-4".

      Parameters:
      suffixInternalPartitionWithLogFormat - Whether to suffix the internal partition with logger format
      Returns:
      This builder.
    • setInternalPartitionSuffix

      public IntradayLoggerBuilder<LOGGER_TYPE> setInternalPartitionSuffix(String internalPartitionSuffix)
      Set a suffix for the internal partition, defaults to no value. Optional.

      The suffix is applied after the computed internal partition, but before the log format (if suffixInternalPartitionWithLogFormat is true).

      Example: If the internal partition would normally have been "ABC", the internal partition suffix is "DEF", and the logger format is version 4, the actual partition used would be: "ABC-DEF-4". If the log format suffix is not set, then the actual partition would be "ABC-DEF".

      Parameters:
      internalPartitionSuffix - the suffix for the computed internal partition
      Returns:
      This builder.
    • makeLogger

      public LOGGER_TYPE makeLogger(@NotNull com.fishlib.configuration.Configuration configuration, @NotNull com.fishlib.io.logger.Logger log)
      Create an IntradayLogger and initialize it according to the specified parameters on this builder.
      • If a columnPartitionValue is provided, it will be used for all rows, regardless of any specified dynamic partition properties or provided columnPartitionFunction.
      • If no columnPartitionValue is provided, the column partition value will be determined either by the date when the logged row is written using the specified time zone, or determined dynamically from the schema and data if the properties specify this (loggerClass.useDynamicPartitions, or processName.useDynamicPartitions=true, or loggerClass.processName.useDynamicPartitions=true).
      • The rows will be written directly to binary log files unless the properties specify to use the log aggregator service (processName.useLogAggregatorService=true or loggerClass.processName.useLogAggregatorService=true) or forceUseLas is true.
      Parameters:
      configuration - Configuration instance for property lookup
      log - Logger to be used during IntradayLogger initialization
      Returns:
      An initialized IntradayLogger.
    • getNodeIdentifier

      public static String getNodeIdentifier(boolean legalize)
      Get the identifier for the local host by calling InetAddress.getLocalHost().getHostName() if it is available, optionally legalizing it for use as a partition identifier by replacing dots with underscores. This will return a Pod name if deployed in a Kubernetes environment.
      Parameters:
      legalize - if true, modify the return value to be a legal partition string
      Returns:
      the local host name, or "UndeterminedHost" if it can't be determined
    • getNodeIdentifier

      public static String getNodeIdentifier()
      Get the identifier for the local node if it is available
      Returns:
      the local host name, or "UndeterminedHost" if it can't be determined
    • getInternalPartitionFromConfig

      @Nullable public static String getInternalPartitionFromConfig()
      Gets the LOCAL_INTERNAL_PARTITION_PROPERTY from the Configuration if it is defined. If the property value starts with env: then the part of the property after that prefix will be used to look up and return an environment variable. For example, if configuring a property value of env:NODE_IP this method will return the value of the NODE_IP environment variable, with all '.' characters replaced with a '_'. Will return null if property is not present, or if there is no environment variable whose name matches the part of the property after env: prefix.
      Returns:
      The value to be used as the internal partition. Will be null if LOCAL_INTERNAL_PARTITION_PROPERTY is not defined, or the environment variable it references is not defined.
    • getInternalPartitionForLogs

      @NotNull public String getInternalPartitionForLogs(LOGGER_TYPE logger, String pidstr)
      Determine an appropriate internal partition that can be used for writing logs. Calls getInternalPartitionFromConfig() and uses that value, if a config value is present. If not, then the partition will be the value obtained by calling getNodeIdentifier(), with any period characters replaced with underscores.
      Returns:
      the internal partition as described above.
    • getInternalPartitionForLogs

      @NotNull public static String getInternalPartitionForLogs()