or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/maven-org-slf4j--slf4j-nop

SLF4J NOP Provider - A no-operation implementation of the SLF4J logging facade that silently discards all logging operations

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.slf4j/slf4j-nop@2.0.x

To install, run

npx @tessl/cli install tessl/maven-org-slf4j--slf4j-nop@2.0.0

0

# SLF4J NOP Provider

1

2

SLF4J NOP Provider is a specialized implementation of the Simple Logging Facade for Java (SLF4J) that provides no-operation logging behavior. All logging operations are silently discarded without any output or side effects, making it ideal for applications that need to satisfy SLF4J API dependencies while completely disabling logging functionality.

3

4

## Package Information

5

6

- **Package Name**: slf4j-nop

7

- **Package Type**: Maven

8

- **Group ID**: org.slf4j

9

- **Artifact ID**: slf4j-nop

10

- **Language**: Java

11

- **Installation**: Add to Maven `pom.xml`: `<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-nop</artifactId><version>2.0.17</version></dependency>`

12

13

## Core Imports

14

15

```java

16

import org.slf4j.Logger;

17

import org.slf4j.LoggerFactory;

18

import org.slf4j.Marker;

19

import org.slf4j.MarkerFactory;

20

import org.slf4j.MDC;

21

```

22

23

## Basic Usage

24

25

```java

26

import org.slf4j.Logger;

27

import org.slf4j.LoggerFactory;

28

29

public class MyApplication {

30

private static final Logger logger = LoggerFactory.getLogger(MyApplication.class);

31

32

public void doSomething() {

33

// All logging calls are silently discarded - zero performance overhead

34

logger.info("This message will be discarded");

35

logger.debug("Debug information - also discarded");

36

logger.error("Even errors are discarded");

37

38

// Level checks always return false

39

if (logger.isDebugEnabled()) { // Always false

40

// This block never executes

41

logger.debug("Expensive debug operation");

42

}

43

}

44

}

45

```

46

47

## Architecture

48

49

The NOP provider implements the SLF4J Service Provider Interface (SPI) with no-operation behavior:

50

51

- **NOPServiceProvider**: Main service provider that implements `SLF4JServiceProvider`

52

- **NOPLoggerFactory**: Returns singleton NOP logger instances

53

- **NOPLogger**: All logging methods are no-ops, level checks return false

54

- **NOPMDCAdapter**: Mapped Diagnostic Context operations have no effect

55

56

## Capabilities

57

58

### Logger Factory

59

60

Access to logger instances through the standard SLF4J factory pattern.

61

62

```java { .api }

63

public class LoggerFactory {

64

public static Logger getLogger(String name);

65

public static Logger getLogger(Class<?> clazz);

66

}

67

```

68

69

### Logger Interface

70

71

All logging methods are implemented as no-operations that silently discard input.

72

73

```java { .api }

74

public interface Logger {

75

// Level checking methods - all return false

76

boolean isTraceEnabled();

77

boolean isDebugEnabled();

78

boolean isInfoEnabled();

79

boolean isWarnEnabled();

80

boolean isErrorEnabled();

81

boolean isTraceEnabled(Marker marker);

82

boolean isDebugEnabled(Marker marker);

83

boolean isInfoEnabled(Marker marker);

84

boolean isWarnEnabled(Marker marker);

85

boolean isErrorEnabled(Marker marker);

86

87

// Basic logging methods - all no-ops

88

void trace(String msg);

89

void trace(String format, Object arg);

90

void trace(String format, Object arg1, Object arg2);

91

void trace(String format, Object... arguments);

92

void trace(String msg, Throwable t);

93

94

void debug(String msg);

95

void debug(String format, Object arg);

96

void debug(String format, Object arg1, Object arg2);

97

void debug(String format, Object... arguments);

98

void debug(String msg, Throwable t);

99

100

void info(String msg);

101

void info(String format, Object arg);

102

void info(String format, Object arg1, Object arg2);

103

void info(String format, Object... arguments);

104

void info(String msg, Throwable t);

105

106

void warn(String msg);

107

void warn(String format, Object arg);

108

void warn(String format, Object arg1, Object arg2);

109

void warn(String format, Object... arguments);

110

void warn(String msg, Throwable t);

111

112

void error(String msg);

113

void error(String format, Object arg);

114

void error(String format, Object arg1, Object arg2);

115

void error(String format, Object... arguments);

116

void error(String msg, Throwable t);

117

118

// Marker-based logging methods - all no-ops

119

void trace(Marker marker, String msg);

120

void trace(Marker marker, String format, Object arg);

121

void trace(Marker marker, String format, Object arg1, Object arg2);

122

void trace(Marker marker, String format, Object... arguments);

123

void trace(Marker marker, String msg, Throwable t);

124

125

void debug(Marker marker, String msg);

126

void debug(Marker marker, String format, Object arg);

127

void debug(Marker marker, String format, Object arg1, Object arg2);

128

void debug(Marker marker, String format, Object... arguments);

129

void debug(Marker marker, String msg, Throwable t);

130

131

void info(Marker marker, String msg);

132

void info(Marker marker, String format, Object arg);

133

void info(Marker marker, String format, Object arg1, Object arg2);

134

void info(Marker marker, String format, Object... arguments);

135

void info(Marker marker, String msg, Throwable t);

136

137

void warn(Marker marker, String msg);

138

void warn(Marker marker, String format, Object arg);

139

void warn(Marker marker, String format, Object arg1, Object arg2);

140

void warn(Marker marker, String format, Object... arguments);

141

void warn(Marker marker, String msg, Throwable t);

142

143

void error(Marker marker, String msg);

144

void error(Marker marker, String format, Object arg);

145

void error(Marker marker, String format, Object arg1, Object arg2);

146

void error(Marker marker, String format, Object... arguments);

147

void error(Marker marker, String msg, Throwable t);

148

149

// Utility method

150

String getName(); // Returns "NOP"

151

}

152

```

153

154

### Marker Factory

155

156

Creates markers for tagged logging (markers function normally, but tagged logging calls are still discarded).

157

158

```java { .api }

159

public class MarkerFactory {

160

public static Marker getMarker(String name);

161

}

162

```

163

164

### Mapped Diagnostic Context (MDC)

165

166

Provides contextual information storage - all operations are no-ops in NOP provider.

167

168

```java { .api }

169

public class MDC {

170

public static void put(String key, String val); // No-op

171

public static String get(String key); // Always returns null

172

public static void remove(String key); // No-op

173

public static void clear(); // No-op

174

public static MDCCloseable putCloseable(String key, String val); // Returns no-op closeable

175

176

public interface MDCCloseable extends AutoCloseable {

177

void close(); // No-op

178

}

179

}

180

```

181

182

### Service Provider Interface

183

184

Internal SPI implementation - not typically used directly by applications.

185

186

```java { .api }

187

public interface SLF4JServiceProvider {

188

ILoggerFactory getLoggerFactory();

189

IMarkerFactory getMarkerFactory();

190

MDCAdapter getMDCAdapter();

191

String getRequestedApiVersion();

192

void initialize();

193

}

194

195

public class NOPServiceProvider implements SLF4JServiceProvider {

196

public static final String REQUESTED_API_VERSION = "2.0.99";

197

198

public NOPServiceProvider();

199

public ILoggerFactory getLoggerFactory();

200

public IMarkerFactory getMarkerFactory();

201

public MDCAdapter getMDCAdapter();

202

public String getRequestedApiVersion();

203

public void initialize(); // No-op

204

}

205

```

206

207

## Types

208

209

```java { .api }

210

public interface Marker extends java.io.Serializable {

211

String getName();

212

void add(Marker reference);

213

boolean remove(Marker reference);

214

boolean hasChildren();

215

boolean hasReferences();

216

Iterator<Marker> iterator();

217

boolean contains(Marker other);

218

boolean contains(String name);

219

}

220

221

public interface ILoggerFactory {

222

Logger getLogger(String name);

223

}

224

225

public interface IMarkerFactory {

226

Marker getMarker(String name);

227

boolean exists(String name);

228

boolean detachMarker(String name);

229

Marker getDetachedMarker(String name);

230

}

231

232

public interface MDCAdapter {

233

void put(String key, String val);

234

String get(String key);

235

void remove(String key);

236

void clear();

237

Map<String, String> getCopyOfContextMap();

238

void setContextMap(Map<String, String> contextMap);

239

void pushByKey(String key, String value);

240

String popByKey(String key);

241

Deque<String> getCopyOfDequeByKey(String key);

242

void clearDequeByKey(String key);

243

}

244

```

245

246

## Usage Examples

247

248

### Basic Logging

249

250

```java

251

import org.slf4j.Logger;

252

import org.slf4j.LoggerFactory;

253

254

public class BusinessLogic {

255

private static final Logger logger = LoggerFactory.getLogger(BusinessLogic.class);

256

257

public void processOrder(String orderId) {

258

logger.info("Processing order: {}", orderId); // Silently discarded

259

260

try {

261

// Business logic here

262

logger.debug("Order processing completed"); // Silently discarded

263

} catch (Exception e) {

264

logger.error("Failed to process order: " + orderId, e); // Silently discarded

265

}

266

}

267

}

268

```

269

270

### Marker-based Logging

271

272

```java

273

import org.slf4j.Logger;

274

import org.slf4j.LoggerFactory;

275

import org.slf4j.Marker;

276

import org.slf4j.MarkerFactory;

277

278

public class SecurityService {

279

private static final Logger logger = LoggerFactory.getLogger(SecurityService.class);

280

private static final Marker SECURITY = MarkerFactory.getMarker("SECURITY");

281

282

public void authenticate(String username) {

283

logger.info(SECURITY, "Authentication attempt for user: {}", username); // Silently discarded

284

285

// Authentication logic

286

logger.warn(SECURITY, "Failed login attempt for: {}", username); // Silently discarded

287

}

288

}

289

```

290

291

### Conditional Logging

292

293

```java

294

import org.slf4j.Logger;

295

import org.slf4j.LoggerFactory;

296

297

public class DataProcessor {

298

private static final Logger logger = LoggerFactory.getLogger(DataProcessor.class);

299

300

public void processData(List<String> data) {

301

// Performance optimization - check if debug is enabled before expensive operations

302

if (logger.isDebugEnabled()) { // Always returns false with NOP provider

303

// This block never executes, avoiding expensive string operations

304

logger.debug("Processing {} items: {}", data.size(), data.toString());

305

}

306

307

// Process data...

308

}

309

}

310

```

311

312

### MDC Context

313

314

```java

315

import org.slf4j.Logger;

316

import org.slf4j.LoggerFactory;

317

import org.slf4j.MDC;

318

319

public class RequestProcessor {

320

private static final Logger logger = LoggerFactory.getLogger(RequestProcessor.class);

321

322

public void handleRequest(String requestId) {

323

MDC.put("requestId", requestId); // No-op

324

325

try {

326

logger.info("Handling request"); // Silently discarded

327

// Request processing logic

328

} finally {

329

MDC.clear(); // No-op

330

}

331

}

332

333

public void handleRequestWithCloseable(String requestId) {

334

try (MDC.MDCCloseable closeable = MDC.putCloseable("requestId", requestId)) { // Returns no-op closeable

335

logger.info("Handling request with closeable MDC"); // Silently discarded

336

// Request processing logic

337

} // Closeable.close() is no-op

338

}

339

}

340

```

341

342

## Error Handling

343

344

The NOP provider does not throw any exceptions from logging operations. All methods silently accept and discard input parameters. This ensures that applications remain functional even when logging is completely disabled.

345

346

Common patterns:

347

- All logging method calls succeed silently

348

- Level check methods always return `false`

349

- MDC operations have no effect and `get()` always returns `null`

350

- No configuration is required or possible