|
| 1 | +classdef OtlpFileLogRecordExporter < opentelemetry.sdk.logs.LogRecordExporter |
| 2 | +% OtlpFileLogRecordExporter exports log records in OpenTelemetry Protocol format to |
| 3 | +% one or more files. |
| 4 | + |
| 5 | +% Copyright 2024 The MathWorks, Inc. |
| 6 | + |
| 7 | + properties |
| 8 | + FileName (1,1) string = "logs-%N.jsonl" % Output file name |
| 9 | + AliasName (1,1) string = "logs-latest.jsonl" % Alias file name, which is the latest file in rotation |
| 10 | + FlushInterval (1,1) duration = seconds(30) % Time interval between log record exports |
| 11 | + FlushRecordCount (1,1) double = 256 % Maximum number of records before exporting |
| 12 | + MaxFileSize (1,1) double = 20971520 % Maximum output file size |
| 13 | + MaxFileCount (1,1) double = 10 % Maximum number of output files, written to in rotation. |
| 14 | + end |
| 15 | + |
| 16 | + properties (Access=private, Constant) |
| 17 | + Validator = opentelemetry.exporters.otlp.OtlpFileValidator |
| 18 | + end |
| 19 | + |
| 20 | + methods |
| 21 | + function obj = OtlpFileLogRecordExporter(optionnames, optionvalues) |
| 22 | + % OtlpFileLogRecordExporter exports log records in OpenTelemetry |
| 23 | + % Protocol format to one or more files. |
| 24 | + % EXP = OPENTELEMETRY.EXPORTERS.OTLP.OTLPFILELOGRECORDEXPORTER |
| 25 | + % creates an exporter that uses default configurations. |
| 26 | + % |
| 27 | + % EXP = |
| 28 | + % OPENTELEMETRY.EXPORTERS.OTLP.OTLPFILELOGRECORDEXPORTER(PARAM1, |
| 29 | + % VALUE1, PARAM2, VALUE2, ...) specifies optional parameter |
| 30 | + % name/value pairs. Parameters are: |
| 31 | + % "FileName" - Output file name. Can contain |
| 32 | + % pattern placeholders. Default |
| 33 | + % name is "logs-%N.jsonl" |
| 34 | + % "AliasName" - Alias file name, which is the |
| 35 | + % latest file in rotation. Can |
| 36 | + % contain pattern placeholders. |
| 37 | + % Default name is "logs-latest.jsonl" |
| 38 | + % "FlushInterval" - Time interval between log record |
| 39 | + % exports, represented as a |
| 40 | + % duration. Default is 30 seconds. |
| 41 | + % "FlushRecordCount" - Maximum number of records before |
| 42 | + % exporting. When the number of |
| 43 | + % records exceed this value, an |
| 44 | + % export will be started. Default |
| 45 | + % is 256. |
| 46 | + % "MaxFileSize" - Maximum output file size |
| 47 | + % "MaxFileCount" - Maximum number of output files, |
| 48 | + % written to in rotation. Default |
| 49 | + % is 10. |
| 50 | + % |
| 51 | + % Supported pattern placeholders in FileName and AliasName are: |
| 52 | + % %Y: year as a 4 digit decimal number |
| 53 | + % %y: last 2 digits of year as a decimal number (range [00,99]) |
| 54 | + % %m: month as a decimal number (range [01,12]) |
| 55 | + % %j: day of the year as a decimal number (range [001,366]) |
| 56 | + % %d: day of the month as a decimal number (range [01,31]) |
| 57 | + % %w: weekday as a decimal number, where Sunday is 0 (range [0-6]) |
| 58 | + % %H: hour as a decimal number, 24 hour clock (range [00-23]) |
| 59 | + % %I: hour as a decimal number, 12 hour clock (range [01,12]) |
| 60 | + % %M: minute as a decimal number (range [00,59]) |
| 61 | + % %S: second as a decimal number (range [00,60]) |
| 62 | + % %F: equivalent to "%Y-%m-%d" (the ISO 8601 date format) |
| 63 | + % %T: equivalent to "%H:%M:%S" (the ISO 8601 time format) |
| 64 | + % %R: equivalent to "%H:%M" |
| 65 | + % %N: rotate index, starting from 0 |
| 66 | + % %n: rotate index, starting from 1 |
| 67 | + % |
| 68 | + % See also |
| 69 | + % OPENTELEMETRY.EXPORTERS.OTLP.OTLPHTTPLOGRECORDEXPORTER, |
| 70 | + % OPENTELEMETRY.EXPORTERS.OTLP.OTLPGRPCLOGRECORDEXPORTER |
| 71 | + arguments (Repeating) |
| 72 | + optionnames (1,:) {mustBeTextScalar} |
| 73 | + optionvalues |
| 74 | + end |
| 75 | + |
| 76 | + |
| 77 | + "libmexclass.opentelemetry.exporters.OtlpFileLogRecordExporterProxy"); |
| 78 | + |
| 79 | + validnames = ["FileName", "AliasName", "FlushInterval", ... |
| 80 | + "FlushRecordCount", "MaxFileSize", "MaxFileCount"]; |
| 81 | + for i = 1:length(optionnames) |
| 82 | + namei = validatestring(optionnames{i}, validnames); |
| 83 | + valuei = optionvalues{i}; |
| 84 | + obj.(namei) = valuei; |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + function obj = set.FileName(obj, fn) |
| 89 | + fn = obj.Validator.validateName(fn, "FileName"); |
| 90 | + obj.Proxy.setFileName(fn); |
| 91 | + obj.FileName = fn; |
| 92 | + end |
| 93 | + |
| 94 | + function obj = set.AliasName(obj, alias) |
| 95 | + alias = obj.Validator.validateName(alias, "AliasName"); |
| 96 | + obj.Proxy.setAliasName(alias); |
| 97 | + obj.AliasName = alias; |
| 98 | + end |
| 99 | + |
| 100 | + function obj = set.FlushInterval(obj, interval) |
| 101 | + obj.Validator.validateFlushInterval(interval); |
| 102 | + obj.Proxy.setFlushInterval(milliseconds(interval)); |
| 103 | + obj.FlushInterval = interval; |
| 104 | + end |
| 105 | + |
| 106 | + function obj = set.FlushRecordCount(obj, count) |
| 107 | + count = obj.Validator.validateScalarPositiveInteger(count, "FlushRecordCount"); |
| 108 | + obj.Proxy.setFlushRecordCount(count); |
| 109 | + obj.FlushRecordCount = count; |
| 110 | + end |
| 111 | + |
| 112 | + function obj = set.MaxFileSize(obj, maxsize) |
| 113 | + maxsize = obj.Validator.validateScalarPositiveInteger(maxsize, "MaxFileSize"); |
| 114 | + obj.Proxy.setMaxFileSize(maxsize); |
| 115 | + obj.MaxFileSize = maxsize; |
| 116 | + end |
| 117 | + |
| 118 | + function obj = set.MaxFileCount(obj, maxfilecount) |
| 119 | + maxfilecount = obj.Validator.validateScalarPositiveInteger(maxfilecount, "MaxFileCount"); |
| 120 | + obj.Proxy.setMaxFileCount(maxfilecount); |
| 121 | + obj.MaxFileCount = maxfilecount; |
| 122 | + end |
| 123 | + end |
| 124 | +end |
0 commit comments