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

br.com.objectos.logging.Logging Maven / Gradle / Ivy

Go to download

The Objectos Logging API. This is the API only, an implementation is needed during runtime.

There is a newer version: 3.1.0
Show newest version
/*
 * Copyright (C) 2021-2022 Objectos Software LTDA.
 *
 * 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.
 */
package br.com.objectos.logging;

public final class Logging {

  /*
  @startuml
  
  ' config
  
  hide empty members
  ' left to right direction
  skinparam genericDisplay old
  ' skinparam monochrome true
  skinparam shadowing false
  ' skinparam style strictuml
  
  ' classes
  
  class DoubleEvent extends Event
  
  abstract class Event {
    + int getKey()
    + Level getLevel()
    + Class getSource()
  }
  
  class Event0 extends Event
  
  class Event1 extends Event {
    + String formatValue(V1 value)
  }
  
  class Event2 extends Event {
    + String formatValue1(V1 value)
    + String formatValue2(V2 value)
  }
  
  class IntEvent extends Event
  
  enum Level {
    TRACE
    DEBUG
    INFO
    WARNING
    ERROR
  }
  
  interface Logger {
    + void log(Event0 m)
    +  void log(Event1 m, V1 v1)
    +  void log(Event2 m, V1 v1, V2 v2)
    + void log(EventDouble m, double v)
    + void log(EventInt m, int v)
    + void log(EventLong m, long v)
  }
  
  class Logging {
    + {static} Event0 info(\lClass source, String key)
    + {static}  Event1 info(\lClass source,\lString key,\lClass v1)
    + {static}  Event1 info(\lClass source,\lString key,\lSerializer v1)
    + {static}  Event2 info(\lClass source,\lString key,\lClass v1,\lClass v2)
    + {static}  Event2 info(\lClass source,\lString key,\lTypeHint v1,\lTypeHint v2)
  }
  
  class LongEvent extends Event
  
  ' ordering
  
  Logging -[hidden]d- Level
  Level -[hidden]d- Logger
  Logger -[hidden]d- Event
  Event -[hidden]d- Event0
  Event0 -[hidden]d- Event1
  Event1 -[hidden]d- Event2
  DoubleEvent -[hidden]d- IntEvent
  IntEvent -[hidden]d- LongEvent
  
  @enduml
  */

  private Logging() {}

  public static void abbreviate(StringBuilder out, String source, int length) {
    String result;
    result = source;

    int resultLength;
    resultLength = result.length();

    if (resultLength > length) {
      int start;
      start = resultLength - length;

      result = result.substring(start, resultLength);
    }

    out.append(result);

    int pad;
    pad = length - result.length();

    for (int i = 0; i < pad; i++) {
      out.append(' ');
    }
  }

  public static String format(Object o) {
    if (o != null) {
      return o.toString();
    } else {
      return "null";
    }
  }

  public static void pad(StringBuilder out, String source, int length) {
    String result;
    result = source;

    if (result.length() > length) {
      result = result.substring(0, length);
    }

    out.append(result);

    int pad;
    pad = length - result.length();

    for (int i = 0; i < pad; i++) {
      out.append(' ');
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy