syntax = "proto3";

package devvit.plugin.logger;

import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";

option go_package = "github.snooguts.net/reddit/reddit-devplatform-monorepo/go-common/generated/protos/types/devvit/plugin/logger";
option java_package = "com.reddit.devvit.plugin.logger";

enum Severity {
  // Debug logs should never be committed.
  //
  // These logs are always enabled in development builds but disabled in
  // production.
  DEBUG = 0;
  // Informational logs should be used to mark significant non-erroneous events.
  // Little information is significant.
  //
  // These logs are enabled by default in development builds but may be
  // disabled in production.
  INFO = 1;
  // Warnings should be reported as long as they do not contain sensitive data.
  //
  // These logs are always enabled.
  WARN = 2;
  // Errors should always be reported as long as they do not contain sensitive
  // data.
  ERROR = 3;
  // Verbose logs are useful for tracing but usually a hindrance for others not
  // working where the log is placed. Keep our logs clean and add with care.
  //
  // These logs are disabled by default in all environments but can be enabled.
  VERBOSE = 4;
}

message LogErrorMessage {
  string message = 1;
  string name = 2;
  google.protobuf.StringValue file_name = 3;
  google.protobuf.UInt32Value line_number = 4;
  google.protobuf.UInt32Value column_number = 5;
  google.protobuf.StringValue stack = 6;
  google.protobuf.Timestamp timestamp = 7;

  // to-do: add labels like LogEventMessage.
  // Deprecated 2023-01-25: Use labels instead.
  repeated string tags = 8 [deprecated = true];
}

// A notable event or historical record for analytics and security.
//
// Do not record sensitive data.
message LogEventMessage {
  // The event kind. Events with the same type are considered instances of that
  // event. Eg, 'AppLoad' or 'AppHTTPRequest'.
  //
  // Unexpected event types may not be logged.
  string type = 1;

  /** The occurence time. */
  google.protobuf.Timestamp timestamp = 2;

  // Optional additional indexed information. Eg, 'direction' → 'Up' or
  // 'appName' → 'com.example.test'.
  //
  // Unexpected label keys may be stripped.
  //
  // Labels and data are the same except that labels are indexed.
  map<string, string> labels = 3;

  // Optional additional non-indexed information. Eg, 'dynamicString' → 'abc'
  // 'verboseDetail' -> '123'.
  //
  // Any key-value may safely be included without coordination.
  //
  // Labels and data are the same except that labels are indexed.
  map<string, string> data = 4;
}

message LogMessage {
  Severity severity = 1;
  string message = 2;
  // Most service implementations default to call time if a timestamp is not
  // provided.
  google.protobuf.Timestamp timestamp = 3;

  // to-do: add labels like LogEventMessage.
  // Deprecated 2023-01-25: Use labels instead.
  repeated string tags = 4 [deprecated = true];
}

service Logger {
  rpc Error(LogErrorMessage) returns (LogErrorResponse);

  // Record a notable event or historical record for analytics and security.
  //
  // @internal
  // Deprecated 2026-02-13: hasn't been used in a long time, callers removed.
  rpc Event(LogEventMessage) returns (LogEventResponse) {
    option deprecated = true;
  }

  rpc Log(LogMessage) returns (LogResponse);

  rpc LogBatch(LogMessages) returns (LogResponse);

  // Send log messages in a stream rather than unary calls.
  // This can be useful for guaranteeing ordering of received log messages.
  rpc LogStream(stream LogMessage) returns (LogResponse);
}

message LogMessages {
  repeated LogMessage messages = 1;
}

message LogErrorResponse {}
message LogEventResponse {}
message LogResponse {}
