All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.salesforce.functions.jvm.runtime.logger.Utils Maven / Gradle / Ivy

There is a newer version: 1.1.7
Show newest version
/*
 * Copyright (c) 2022, salesforce.com, inc.
 * All rights reserved.
 * SPDX-License-Identifier: BSD-3-Clause
 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
 */
package com.salesforce.functions.jvm.runtime.logger;

import static com.salesforce.functions.jvm.runtime.logger.Constants.LOGGER_NAME_SEGMENT_DELIMITER;

import java.util.regex.Pattern;

public class Utils {

  public static String shortenLoggerName(String loggerName, int maxLength) {
    String[] loggerNameSegments = loggerName.split(Pattern.quote(LOGGER_NAME_SEGMENT_DELIMITER));

    String result = "";
    for (int i = 0; i < loggerNameSegments.length; i++) {
      result = String.join(LOGGER_NAME_SEGMENT_DELIMITER, loggerNameSegments);

      if (result.length() <= maxLength) {
        break;
      }

      if (loggerNameSegments[i].length() > 1) {
        loggerNameSegments[i] = loggerNameSegments[i].substring(0, 1);
      }
    }

    return result;
  }

  private Utils() {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy