All Products
Search
Document Center

Simple Log Service:Color functions

Last Updated:Jun 04, 2026

Learn the syntax and usage of color functions in Log Service.

Log Service supports the following color functions.

Important
  • In a Log Service analytic statement, you must enclose strings in single quotation marks ('). Characters that are not enclosed in single quotation marks or are enclosed in double quotation marks ("") are treated as a field name or column name. For example, 'status' represents the string status, whereas status or "status" represents the log field named status.

  • The Log Service console does not render color function results correctly. Display results in a terminal instead.

    • Console display: The console shows ANSI escape codes as raw characters, such as \e[38;5;1m, instead of rendering colors.

    • Terminal display

      mysql> select pv,bar(pv/10.0,10 , color(0,50,100,  rgb(255,0,0), rgb(0,255,0)), rgb(0,255,0)) from(select * from (VALUES (0),(1), (2), (3), (4), (5), (6), (7),(8),(9)) AS X(pv));
      +------+----------------------------------------------------------------------+
      | pv   | _col1                                                                |
      +------+----------------------------------------------------------------------+
      |    0 |                                                                      |
      |    1 | █                                                                    |
      |    2 | ██                                                                   |
      |    3 | ███                                                                  |
      |    4 | ████                                                                 |
      |    5 | █████                                                                |
      |    6 | ██████                                                               |
      |    7 | ███████                                                              |
      |    8 | ████████                                                             |
      |    9 | █████████                                                            |
      +------+----------------------------------------------------------------------+
      10 rows in set (0.21 sec)

Function

Syntax

Description

SQL support

SPL support

bar function

bar(x, width)

Returns a bar chart segment based on x with a specified width and a default red-to-green gradient.

×

bar(x, width, low_color, high_color)

Returns a bar chart segment based on x with a specified width and custom start and end colors.

×

color function

color(string)

Converts a color string to the color type.

×

color(x, low, high, low_color, high_color)

Weighs low_color and high_color by the proportion of x between low and high, and returns a color between low_color and high_color.

×

color(y, low_color, high_color)

Uses y to specify the proportions of low_color and high_color and returns a color between low_color and high_color.

×

render function

render(boolean expression)

Returns a green check mark (✓) if the boolean expression is true, or a red cross (✗) otherwise.

×

render(x, color)

Renders results in a custom color.

×

rgb function

rgb(red, green, blue)

Returns a color value based on RGB values.

×

bar function

The bar function draws an ANSI bar chart.

Syntax

  • Returns a bar chart segment based on x with a specified width and a default red-to-green gradient.

    bar(x, width)
  • Returns a bar chart segment based on x with a specified width and custom start and end colors.

    bar(x, width, low_color, high_color)

Parameters

Parameter

Description

x

The proportion of the bar to render. The value must be a DOUBLE in the range [0, 1].

width

The width of the full ANSI bar chart.

low_color

The RGB value of the start color in the color gradient.

high_color

The RGB value of the end color in the color gradient.

Return value type

varchar

Examples

  • Example 1: Calculate the hourly PV ratio and display it as an ANSI bar chart.

    • Analytic statement

      * |
      SELECT
        Method,
        bar(pv/m,100)
      FROM(
          SELECT
            *,
            max(pv) over() AS m
          FROM(
              SELECT
                Method,
                count(1) AS pv
              FROM         internal-operation_log
              WHERE
                __date__ > '2021-09-10 00:00:00'
                AND __date__ < '2021-09-10 01:00:00'
              GROUP BY
                Method
            )
        )
    • Query and analysis results (console): The _col1 column displays the ANSI bar chart generated by the bar function.

    • Query and analysis results (terminal)

      +-----------------+----------------------------------------------+
      | GetProjectLogs  | ████████                                     |
      | GetLogStoreLogs | ████████████████████████████████████████████ |
      +-----------------+----------------------------------------------+
      2 rows in set (8.99 sec)
  • Example 2: Draw an ANSI bar chart with a width of 50 using a white-to-red gradient.

    • Analytic statement

      * | SELECT bar(1,50,rgb(255,255,255),rgb(255,0,0))
    • Query and analysis results (console): The _col0 column contains ANSI escape codes that render as a white-to-red gradient bar.

    • Query and analysis results (terminal)

      +------+------+
      | _col0 | _col0 |
      +------+------+
      | [white to red gradient bar] |      |
      +------+------+
      1 row in set (0.20 sec)

color function

The color function returns the color corresponding to a specified value.

Syntax

  • Converts a color string to the color type.

    color(string)
  • The proportion of x between low and high determines the weights for low_color and high_color, and the function then returns a color between low_color and high_color.

    color(x, low, high, low_color, high_color)
  • Uses y to specify the proportion of low_color and high_color, and returns a color between low_color and high_color.

    color(y, low_color, high_color)

Parameters

Parameter

Description

x

A DOUBLE value.

y

A DOUBLE value in the range [0, 1].

low

The minimum value of the range, a DOUBLE.

high

The maximum value of the range, a DOUBLE.

low_color

The RGB value of the start color in the color gradient.

high_color

The RGB value of the end color in the color gradient.

string

A color name string (for example, black, red) or a CSS-style RGB value (for example, #000).

Return value type

color

Examples

  • Example 1: Convert a color string to the color type.

    • Analytic statement

      * | SELECT color('#000')
    • Query and analysis results (console): The result is #000000.

    • Query and analysis results (terminal)

      mysql> SELECT color('#000');
      +---------+
      | _col0   |
      +---------+
      | #000000 |
      +---------+
      1 row in set (0.21 sec)
  • Example 2: Generate a colored ANSI bar chart from the remainder of the request_length field.

    • Analytic statement

      *|SELECT x,bar(10,10, color(x, 0,10, rgb(255,0,0), rgb(0,255,0)), rgb(0,255,0)) FROM(SELECT  *FROM (SELECT  request_length%10 x FROM  log))
    • Query and analysis results (console): The x column shows the numeric value, and the _col1 column displays a bar chart with colors transitioning from red to green based on x.

    • Query and analysis results (terminal)

      | x    | _col1                          |
      |------|--------------------------------|
      |    1 | [colored gradient bar]         |
      |    6 | [colored gradient bar]         |
      |    4 | [colored gradient bar]         |
      |    7 | [colored gradient bar]         |
      |    7 | [colored gradient bar]         |
      |    0 | [colored gradient bar]         |
      6 rows in set (0.21 sec)
  • Example 3: Generate an ANSI bar chart with a proportional starting color.

    • Analytic statement

      *|SELECT bar(10,10, color(0.3, rgb(255,255,255), rgb(255,0,0)), rgb(0,255,0))
    • Query and analysis results (console): The result contains ANSI escape codes that display a gradient color bar.

    • Query and analysis results (terminal)

      mysql> select bar(10,10 , color(0.3,  rgb(255,255,255), rgb(255,0,0)), rgb(0,255,0));
      +----------------------------------------------------------------------+
      | _col0                                                                |
      +----------------------------------------------------------------------+
      | ██████████                                                           |
      +----------------------------------------------------------------------+
      1 row in set (0.21 sec)

render function

The render function formats output with colors or symbols.

Syntax

  • Returns a green check mark (✓) if the boolean expression is true, or a red cross (✗) otherwise.

    render(boolean expression)
  • Renders results in a custom color.

    render(x, color)

Parameters

Parameter

Description

boolean expression

The boolean expression to evaluate.

x

The INTEGER value to render.

color

The color to use for rendering. This parameter is of the color type.

Return value type

varchar

Examples

  • Example 1: Check whether the PV count is less than 1,000. Returns ✓ if true.

    • Analytic statement

      * | SELECT render(count(*)<1000)
    • Query and analysis results (console): The console shows ANSI escape codes as raw characters, such as \e[38;5;1m, instead of rendering colors.

    • Query and analysis results (terminal)

      mysql> select render(count(*)<1000);
      +------------------+
      | _col0            |
      +------------------+
      | ✓                |
      +------------------+
      1 row in set (0.22 sec)
  • Example 2: Count total logs and render the result in green.

    • Analytic statement

      * | SELECT render(count(*),rgb(48,169,16))
    • Query and analysis results (console)

      _col0
      \e[38;5;70m1\e[0m
    • Query and analysis results (terminal)

      mysql> select render(count(*),rgb(48,169,16));
      +----------------+
      | _col0          |
      +----------------+
      | 1 |
      +----------------+
      1 row in set (0.21 sec)

rgb function

The rgb function creates a color from specified RGB values.

Syntax

rgb(red, green, blue)

Parameters

Parameter

Description

red

The red component of the color, an integer from 0 to 255.

green

The green component of the color, an integer from 0 to 255.

blue

The blue component of the color, an integer from 0 to 255.

Return value type

color

Examples

Returns a color based on RGB values.

  • Analytic statement

    *|SELECT rgb(255,0,0)
  • Query and analysis results (console): The _col0 column returns #ff0000.

  • Query and analysis results (terminal)

    select rgb(255,0,0);
    +---------+
    | _col0   |
    +---------+
    | #ff0000 |
    +---------+
    1 row in set (0.21 sec)