Ether Framework
Unified API docs for Ether modules
Loading...
Searching...
No Matches
EtherLog.java
Go to the documentation of this file.
1package dev.rafex.ether.logging.core.logger;
2
3/*-
4 * #%L
5 * ether-logging-core
6 * %%
7 * Copyright (C) 2025 - 2026 Raúl Eduardo González Argote
8 * %%
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 * #L%
27 */
28
29import java.util.logging.Level;
30import java.util.logging.Logger;
31
32import dev.rafex.ether.logging.core.format.LogMessageFormatter;
33
34public final class EtherLog {
35
36 private static final ClassValue<Logger> LOGGERS = new ClassValue<>() {
37 @Override
38 protected Logger computeValue(final Class<?> type) {
39 return Logger.getLogger(type.getName());
40 }
41 };
42
43 private EtherLog() {
44 }
45
46 public static Logger get(final Class<?> type) {
47 return LOGGERS.get(type);
48 }
49
50 public static void info(final Class<?> type, final String message) {
51 log(type, Level.INFO, null, message);
52 }
53
54 public static void info(final Class<?> type, final String message, final Object... args) {
55 log(type, Level.INFO, null, LogMessageFormatter.format(message, args));
56 }
57
58 public static void info(final Class<?> type, final Throwable cause, final String message, final Object... args) {
59 log(type, Level.INFO, cause, LogMessageFormatter.format(message, args));
60 }
61
62 public static void warn(final Class<?> type, final String message) {
63 log(type, Level.WARNING, null, message);
64 }
65
66 public static void warn(final Class<?> type, final String message, final Object... args) {
67 log(type, Level.WARNING, null, LogMessageFormatter.format(message, args));
68 }
69
70 public static void warn(final Class<?> type, final Throwable cause, final String message, final Object... args) {
71 log(type, Level.WARNING, cause, LogMessageFormatter.format(message, args));
72 }
73
74 public static void error(final Class<?> type, final String message) {
75 log(type, Level.SEVERE, null, message);
76 }
77
78 public static void error(final Class<?> type, final String message, final Object... args) {
79 log(type, Level.SEVERE, null, LogMessageFormatter.format(message, args));
80 }
81
82 public static void error(final Class<?> type, final String message, final Throwable cause) {
83 log(type, Level.SEVERE, cause, message);
84 }
85
86 public static void error(final Class<?> type, final Throwable cause, final String message, final Object... args) {
87 log(type, Level.SEVERE, cause, LogMessageFormatter.format(message, args));
88 }
89
90 public static void debug(final Class<?> type, final String message) {
91 log(type, Level.FINE, null, message);
92 }
93
94 public static void debug(final Class<?> type, final String message, final Object... args) {
95 log(type, Level.FINE, null, LogMessageFormatter.format(message, args));
96 }
97
98 public static void debug(final Class<?> type, final Throwable cause, final String message, final Object... args) {
99 log(type, Level.FINE, cause, LogMessageFormatter.format(message, args));
100 }
101
102 private static void log(final Class<?> type, final Level level, final Throwable cause, final String message) {
103 final var logger = get(type);
104 if (!logger.isLoggable(level)) {
105 return;
106 }
107 if (cause == null) {
108 logger.log(level, message);
109 return;
110 }
111 logger.log(level, message, cause);
112 }
113}
static String format(final String message, final Object... args)
static void warn(final Class<?> type, final Throwable cause, final String message, final Object... args)
Definition EtherLog.java:70
static void error(final Class<?> type, final Throwable cause, final String message, final Object... args)
Definition EtherLog.java:86
static void error(final Class<?> type, final String message, final Throwable cause)
Definition EtherLog.java:82
static void debug(final Class<?> type, final Throwable cause, final String message, final Object... args)
Definition EtherLog.java:98
static void warn(final Class<?> type, final String message)
Definition EtherLog.java:62
static void info(final Class<?> type, final String message)
Definition EtherLog.java:50
static void info(final Class<?> type, final Throwable cause, final String message, final Object... args)
Definition EtherLog.java:58
static void error(final Class<?> type, final String message)
Definition EtherLog.java:74
static void error(final Class<?> type, final String message, final Object... args)
Definition EtherLog.java:78
static void warn(final Class<?> type, final String message, final Object... args)
Definition EtherLog.java:66
static void debug(final Class<?> type, final String message)
Definition EtherLog.java:90
static void debug(final Class<?> type, final String message, final Object... args)
Definition EtherLog.java:94
static void info(final Class<?> type, final String message, final Object... args)
Definition EtherLog.java:54