// Copyright 2017 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

// $title: Stdio
// $description: Adapter to locally output logs and metrics.
// $location: https://istio.io/docs/reference/config/policy-and-telemetry/adapters/stdio.html
// $supported_templates: logentry,metric
// $aliases:
// $  - /docs/reference/config/adapters/stdio.html

// The `stdio` adapter enables Istio to output logs and metrics to
// the local machine. Logs and metrics can be directed to Mixer's
// standard output stream, standard error stream, or to any locally
// reachable file. When outputting to files, you can enable file rotation
// such that the adapter will automatically manage a set of file backups
// as data is generated.
//
// This adapter supports the [logentry template](https://istio.io/docs/reference/config/policy-and-telemetry/templates/logentry/).
// and the [metric template](https://istio.io/docs/reference/config/policy-and-telemetry/templates/metric/).
package adapter.stdio.config;

import "gogoproto/gogo.proto";

option go_package = "config";
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.equal_all) = false;
option (gogoproto.gostring_all) = false;

// Configuration format for the `stdio` adapter
message Params {
    // Stream is used to select between different log output sinks.
    enum Stream {
        // Output to the Mixer process' standard output stream. This is the default value.
        STDOUT = 0;

        // Output to the Mixer process' standard error stream.
        STDERR = 1;

        // Output to a specific file.
        FILE = 2;

        // Output to a specific rotating file, controlled by the various file rotation options.
        ROTATED_FILE = 3;
    }

    // Importance level for individual items output by this adapter.
    enum Level {
        INFO = 0;       // informational, warning, and error log messages are included
        WARNING = 1;    // warning and error log messages are included
        ERROR = 2;      // only error log messages are included
    }

    // Selects which standard stream to write to for log entries.
    // STDERR is the default Stream.
    Stream log_stream = 1;

    // Maps from severity strings as specified in LogEntry instances to
    // the set of levels supported by this adapter. This defaults to a map of
    //
    // ```
    // "INFORMATIONAL" : INFO,
    // "informational" : INFO,
    // "INFO" : INFO,
    // "info" : INFO,
    // "WARNING" : WARNING,
    // "warning" : WARNING,
    // "WARN": WARNING,
    // "warning": WARNING,
    // "ERROR": ERROR,
    // "error": ERROR,
    // "ERR": ERROR,
    // "err": ERROR,
    // "FATAL": ERROR,
    // "fatal": ERROR,
    // ```
    map<string, Level> severity_levels = 2;

    // The level to assign to metrics being output. Defaults to INFO.
    Level metric_level = 3;

    // Whether to output a console-friendly or json-friendly format. Defaults to true.
    bool output_as_json = 4;

    // The minimum level to output, anything less than this level is ignored. Defaults to INFO (everything).
    Level output_level = 5;

    // The file system path when outputting to a file or rotating file.
    //
    // When using rotated log files, this path is used as a foundational path. This is where log
    // output is normally saved. When a rotation needs to take place because the file got too big
    // or too old, then the file is renamed by appending a timestamp to the name. Such renamed
    // files are called backups. Once a backup has been created, output resumes to this path.
    string output_path = 6;

    // The maximum size in megabytes of a log file before it gets
    // rotated. It defaults to 100 megabytes.
    int32 max_megabytes_before_rotation = 7;

    // The maximum number of days to retain old rotated log files based on the
    // timestamp encoded in their filename. Note that a day is defined as 24
    // hours and may not exactly correspond to calendar days due to daylight
    // savings, leap seconds, etc. The default is to remove log files
    // older than 30 days. 0 indicates no limit.
    int32 max_days_before_rotation = 8;

    // The maximum number of old rotated log files to retain.  The default
    // is to retain at most 1000 logs. 0 indicates no limit.
    int32 max_rotated_files = 9;
}
