SLogger

SLogger is a logger

Overview

Slogger resource is a logger resouce. It is built on the Go’s logger package slogger.

Config yaml format becomes like below. And the resource specific spec is defined in in the proto format shown in the Resource Definition.

apiVersion: core/v1
kind: SLogger
metadata:
  name: "default"
  namespace: "default"
spec: {}

Resource Definition

SLogger is defined in the proto/core/v1/slogger.proto

  1syntax = "proto3";
  2package core.v1;
  3
  4import "buf/validate/validate.proto";
  5import "kernel/replacer.proto";
  6import "kernel/resource.proto";
  7
  8option go_package = "github.com/aileron-gateway/aileron-gateway/apis/core/v1";
  9
 10// SLogger resource definition.
 11// apiVersion="core/v1", kind="SLogger".
 12message SLogger {
 13    string          APIVersion = 1 [json_name = "apiVersion"];
 14    string          Kind       = 2 [json_name = "kind"];
 15    kernel.Metadata Metadata   = 3 [json_name = "metadata"];
 16    SLoggerSpec     Spec       = 4 [json_name = "spec"];
 17}
 18
 19// SLoggerSpec is the specifications for the SLogger object.
 20message SLoggerSpec {
 21    // [OPTIONAL]
 22    // LogLevel is the log output level.
 23    // Default is [STDOUT].
 24    LogLevel Level = 1 [json_name = "level"];
 25
 26    // [OPTIONAL]
 27    // LogOutput is the specifications of log output.
 28    // Default values are used if not set.
 29    LogOutputSpec LogOutput = 2 [json_name = "logOutput"];
 30
 31    // [OPTIONAL]
 32    // Unstructured is the flag to use text log, or non-json log.
 33    // Default is [false].
 34    bool Unstructured = 3 [json_name = "unstructured"];
 35
 36    // [OPTIONAL]
 37    // OutputTimeFormat is the timestamp format of the
 38    // "time" field which located on the top level in logs.
 39    // This time indicates the log 'output' time which is
 40    // different from log 'creation' time.
 41    // Use DateFormat and TimeFormat field to specify the
 42    // timestamp format of log 'creation' time.
 43    // Timezone is inherited from the LogOutput.TimeZone.
 44    // Check the following url for the available syntax.
 45    // https://pkg.go.dev/time#pkg-constants
 46    // Default is ["2006-01-02 15:04:05"].
 47    string OutputTimeFormat = 4 [json_name = "outputTimeFormat"];
 48
 49    // [OPTIONAL]
 50    // DateFormat is the timestamp format of the date
 51    // "datetime.date" field in logs.
 52    // Timestamp of the "datetime" indicates the log 'creation' time
 53    // which is different from log 'output' time.
 54    // Timezone is inherited from the LogOutput.TimeZone.
 55    // Check the following url for the available syntax.
 56    // https://pkg.go.dev/time#pkg-constants
 57    // Default is ["2006-01-02"].
 58    string DateFormat = 5 [json_name = "dateFormat"];
 59
 60    // [OPTIONAL]
 61    // TimeFormat is the timestamp format of the time
 62    // "datetime.time" field in logs.
 63    // Timestamp of the "datetime" indicates the log 'creation' time
 64    // which is different from log 'output' time.
 65    // Timezone is inherited from the LogOutput.TimeZone.
 66    // Check the following url for the available syntax.
 67    // https://pkg.go.dev/time#pkg-constants
 68    // Default is ["15:04:05.000"].
 69    string TimeFormat = 6 [json_name = "timeFormat"];
 70
 71    // [OPTIONAL]
 72    // NoLocation is the flag to suppress "location" log field.
 73    // It contains file name, line number and function name.
 74    // Default is [false].
 75    bool NoLocation = 7 [json_name = "noLocation"];
 76
 77    // [OPTIONAL]
 78    // NoDatetime is the flag to suppress "datetime" log field.
 79    // It contains date, time and time zone.
 80    // Default is [false].
 81    bool NoDatetime = 8 [json_name = "noDatetime"];
 82
 83    // [OPTIONAL]
 84    // FieldReplaces is the list of field replace configuration.
 85    // This can be used for log masking.
 86    // Default is not set.
 87    repeated FieldReplacerSpec FieldReplacers = 9 [json_name = "fieldReplacers"];
 88}
 89
 90message FieldReplacerSpec {
 91    // [REQUIRED]
 92    // Field is the field name to replace value.
 93    // Inner fields, if having map structure,
 94    // can be accessed by paath expression
 95    // line "foo.bar.baz".
 96    // Default is not set.
 97    string Field = 1 [json_name = "field"];
 98
 99    // [Optional]
100    // Replacers is the value replace configurations.
101    // If not set, target field is removed from log outpur.
102    // Default is not set, which means remove field.
103    kernel.ReplacerSpec Replacer = 2 [json_name = "replacer"];
104}
105
106// LogOutputSpec is the specification for log output.
107message LogOutputSpec {
108    // [OPTIONAL]
109    // OutputTarget is the destination of log outsput.
110    // Default is [Stdout].
111    OutputTarget OutputTarget = 1 [json_name = "outputTarget"];
112
113    // [OPTIONAL]
114    // LogDir is the log output directory path.
115    // This field is used only for "File" output.
116    // Default is the working directory.
117    string LogDir = 2 [json_name = "logDir"];
118
119    // [OPTIONAL]
120    // LogDir is the log output directory path.
121    // This field is used only for "File" output.
122    // Default is the same as LogDir.
123    string BackupDir = 3 [json_name = "backupDir"];
124
125    // [OPTIONAL]
126    // LogFileName is the base filename of logs.
127    // This field is used only for "File" output.
128    // Default is ["application.log"].
129    string LogFileName = 4 [json_name = "logFileName"];
130
131    // [OPTIONAL]
132    // Cron is the cron expression for time based log rotation.
133    // If not set, time based rotation will be disabled.
134    // Format should be "second minute hour day month week"
135    // or "minute hour day month week".
136    // TZ must be a valid timezone name.
137    // Value ranges are `0-59` for second, `0-59` for minute,
138    // `0-23` for hour, `1-31` for day of month,
139    // `1-12 or JAN-DEC` for month, `0-6 or SUN-SAT` for day of week.
140    // Special caharacters `* / , -` are allowed for all fields.
141    // Timezone can be specified like "TZ=UTC * * * * *".
142    // For example, "0 * * * *" means hourly rotation,
143    // "0 0 * * *" means daily rotation.
144    // Multiple jobs won't be run at the same time.
145    // Default is not set.
146    string Cron = 5 [json_name = "cron"];
147
148    // [OPTIONAL]
149    // RotateSize is the log file size in MiB to be rotated.
150    // This field is used only for "File" output.
151    // Default is [1024], or 1GiB.
152    uint32 RotateSize = 6 [json_name = "rotateSize"];
153
154    // [OPTIONAL]
155    // TimeLayout is the timestamp layout in the backup-ed log files.
156    // This field is used only for "File" output.
157    // Go's time format can be used.
158    // See https://pkg.go.dev/time#pkg-constants for more details.
159    // Default is ["2006-01-02_15-04-05"].
160    string TimeLayout = 7 [json_name = "timeLayout"];
161
162    // [OPTIONAL]
163    // TimeZone is the timezone of the timestamp in the archived log files.
164    // For example, "UTC", "Local", "Asia/Tokyo".
165    // See https://pkg.go.dev/time#LoadLocation for more details.
166    // Default is ["Local"].
167    string TimeZone = 8 [json_name = "timeZone"];
168
169    // [OPTIONAL]
170    // CompressLevel is the gzip compression level.
171    // If 0, no compression applied.
172    // This field is ignored when the output target is not file.
173    // 0 for no compression, 1 for best speed, 9 for best compression,
174    // -2 for huffman only.
175    // See https://pkg.go.dev/compress/gzip#pkg-constants for more detail.
176    // This field is used only for "File" output.
177    // Default is [0], or no compression.
178    int32 CompressLevel = 9 [json_name = "compressLevel", (buf.validate.field).int32 = {gte : -2, lte : 9}];
179
180    // [OPTIONAL]
181    // MaxAge is maximum age of backup logs in seconds.
182    // Backups older than this age will be removed.
183    // This field is used only for "File" output.
184    // This field will be ignored when not set or set to negative.
185    // Default is not set.
186    int32 MaxAge = 10 [json_name = "maxAge"];
187
188    // [OPTIONAL]
189    // MaxBackup is the maximum number of log backups.
190    // Backups will be removed from older one if the number of backups exceeded this value.
191    // This field is used only for "File" output.
192    // This field will be ignored when not set or set to negative.
193    // Default is not set.
194    int32 MaxBackup = 11 [json_name = "maxBackup"];
195
196    // [OPTIONAL]
197    // MaxTotalSize is the maximum total size of backups in MiB.
198    // Backups will be removed from older one if the total file size
199    // exceeded this value.
200    // This field is used only for "File" output.
201    // This field will be ignored when not set.
202    // Default is not set.
203    uint32 MaxTotalSize = 12 [json_name = "maxTotalSize"];
204}
205
206// OutputTarget is the output destination.
207enum OutputTarget {
208    Stdout  = 0;  // Output to standard output.
209    Stderr  = 1;  // Output to standard error output.
210    Discard = 2;  // Discard outputs.
211    File    = 3;  // Output to files.
212}
213
214// LogLevel is the defined log output level.
215enum LogLevel {
216    LogLevelUnknown = 0;  // Log level Unknown.
217    Trace           = 1;  // Log level Trace.
218    Debug           = 2;  // Log level Debug.
219    Info            = 3;  // Log level Info.
220    Warn            = 4;  // Log level Warn.
221    Error           = 5;  // Log level Error.
222    Fatal           = 6;  // Log level Fatal.
223}

最終更新 June 7, 2025: add japanese (f2a41f1)