or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

browser.mdchild-loggers.mdindex.mdlogger-configuration.mdlogger-methods.mdserializers.mdstreams.mdtransports.md

logger-methods.mddocs/

0

# Logger Methods

1

2

Core logging functionality with standard severity levels and structured output formatting. Each method provides flexible parameter handling for objects, messages, and format strings.

3

4

## Capabilities

5

6

### Fatal Level Logging

7

8

Log at 'fatal' level for unrecoverable errors that cause application termination.

9

10

```typescript { .api }

11

/**

12

* Log at 'fatal' level the given message and optional object properties

13

* @param obj - Object to be serialized into the log line

14

* @param msg - Log message, can include format specifiers

15

* @param args - Format string values when msg contains format specifiers

16

*/

17

fatal(obj?: object, msg?: string, ...args: any[]): void;

18

fatal(msg: string, ...args: any[]): void;

19

```

20

21

**Usage Examples:**

22

23

```javascript

24

logger.fatal('Application crashed');

25

logger.fatal({ error: 'ENOMEM' }, 'Out of memory');

26

logger.fatal('Database connection failed: %s', errorMessage);

27

logger.fatal({ userId: 123, action: 'login' }, 'Authentication failed for user');

28

```

29

30

### Error Level Logging

31

32

Log at 'error' level for recoverable errors and exceptions.

33

34

```typescript { .api }

35

/**

36

* Log at 'error' level the given message and optional object properties

37

* @param obj - Object to be serialized into the log line

38

* @param msg - Log message, can include format specifiers

39

* @param args - Format string values when msg contains format specifiers

40

*/

41

error(obj?: object, msg?: string, ...args: any[]): void;

42

error(msg: string, ...args: any[]): void;

43

```

44

45

**Usage Examples:**

46

47

```javascript

48

logger.error('Request validation failed');

49

logger.error({ statusCode: 400 }, 'Bad request received');

50

logger.error('Connection timeout after %d ms', timeout);

51

logger.error(new Error('Database error'), 'Query execution failed');

52

```

53

54

### Warn Level Logging

55

56

Log at 'warn' level for warning conditions that don't prevent operation.

57

58

```typescript { .api }

59

/**

60

* Log at 'warn' level the given message and optional object properties

61

* @param obj - Object to be serialized into the log line

62

* @param msg - Log message, can include format specifiers

63

* @param args - Format string values when msg contains format specifiers

64

*/

65

warn(obj?: object, msg?: string, ...args: any[]): void;

66

warn(msg: string, ...args: any[]): void;

67

```

68

69

**Usage Examples:**

70

71

```javascript

72

logger.warn('Deprecated API endpoint used');

73

logger.warn({ endpoint: '/old-api' }, 'Using deprecated endpoint');

74

logger.warn('High memory usage: %d%%', memoryPercent);

75

```

76

77

### Info Level Logging

78

79

Log at 'info' level for general informational messages about application operation.

80

81

```typescript { .api }

82

/**

83

* Log at 'info' level the given message and optional object properties

84

* @param obj - Object to be serialized into the log line

85

* @param msg - Log message, can include format specifiers

86

* @param args - Format string values when msg contains format specifiers

87

*/

88

info(obj?: object, msg?: string, ...args: any[]): void;

89

info(msg: string, ...args: any[]): void;

90

```

91

92

**Usage Examples:**

93

94

```javascript

95

logger.info('Application started');

96

logger.info({ port: 3000 }, 'Server listening on port');

97

logger.info('Processed %d records in %d ms', count, duration);

98

logger.info({ userId: 123, action: 'login' }, 'User logged in successfully');

99

```

100

101

### Debug Level Logging

102

103

Log at 'debug' level for detailed diagnostic information, typically disabled in production.

104

105

```typescript { .api }

106

/**

107

* Log at 'debug' level the given message and optional object properties

108

* @param obj - Object to be serialized into the log line

109

* @param msg - Log message, can include format specifiers

110

* @param args - Format string values when msg contains format specifiers

111

*/

112

debug(obj?: object, msg?: string, ...args: any[]): void;

113

debug(msg: string, ...args: any[]): void;

114

```

115

116

**Usage Examples:**

117

118

```javascript

119

logger.debug('Processing request');

120

logger.debug({ requestId: 'abc123' }, 'Request details');

121

logger.debug('Cache hit ratio: %d%%', hitRatio);

122

```

123

124

### Trace Level Logging

125

126

Log at 'trace' level for very detailed diagnostic information, including execution paths.

127

128

```typescript { .api }

129

/**

130

* Log at 'trace' level the given message and optional object properties

131

* @param obj - Object to be serialized into the log line

132

* @param msg - Log message, can include format specifiers

133

* @param args - Format string values when msg contains format specifiers

134

*/

135

trace(obj?: object, msg?: string, ...args: any[]): void;

136

trace(msg: string, ...args: any[]): void;

137

```

138

139

**Usage Examples:**

140

141

```javascript

142

logger.trace('Entering function parseRequest');

143

logger.trace({ functionName: 'validateInput' }, 'Function entry');

144

logger.trace('Variable state: %j', variableState);

145

```

146

147

### Silent Level Logging

148

149

No-op function that discards all log messages, used when logging is completely disabled.

150

151

```typescript { .api }

152

/**

153

* No-op function that discards all log messages

154

* @param obj - Ignored object parameter

155

* @param msg - Ignored message parameter

156

* @param args - Ignored additional arguments

157

*/

158

silent(obj?: object, msg?: string, ...args: any[]): void;

159

silent(msg: string, ...args: any[]): void;

160

```

161

162

## Level Management

163

164

### Level Property

165

166

Control the minimum logging level for the logger instance.

167

168

```typescript { .api }

169

/**

170

* Set or get the current logging level

171

* Levels in order: trace(10), debug(20), info(30), warn(40), error(50), fatal(60), silent(Infinity)

172

*/

173

level: string;

174

```

175

176

**Usage Examples:**

177

178

```javascript

179

// Set level

180

logger.level = 'debug';

181

logger.level = 'warn';

182

logger.level = 'silent'; // Disable all logging

183

184

// Get current level

185

console.log(logger.level); // 'info'

186

```

187

188

### Level Value

189

190

Get the numeric value of the current logging level.

191

192

```typescript { .api }

193

/**

194

* Returns the numeric value for the logger instance's logging level

195

* trace=10, debug=20, info=30, warn=40, error=50, fatal=60, silent=Infinity

196

*/

197

readonly levelVal: number;

198

```

199

200

### Level Enabled Check

201

202

Check if a specific log level will produce output.

203

204

```typescript { .api }

205

/**

206

* Utility method for determining if a given log level will write to the destination

207

* @param level - Level to check (string or number)

208

* @returns true if the level is enabled, false otherwise

209

*/

210

isLevelEnabled(level: string | number): boolean;

211

```

212

213

**Usage Examples:**

214

215

```javascript

216

if (logger.isLevelEnabled('debug')) {

217

// Expensive debug computation only if debug is enabled

218

const debugInfo = computeExpensiveDebugInfo();

219

logger.debug({ debugInfo }, 'Debug information');

220

}

221

222

// Check numeric levels

223

if (logger.isLevelEnabled(20)) { // debug level

224

logger.debug('Debug message');

225

}

226

```

227

228

### Level Labels Output

229

230

Control whether levels are output as strings or numbers.

231

232

```typescript { .api }

233

/**

234

* When true, outputs level as string label instead of numeric value in log records

235

* Default: false (outputs numeric values)

236

*/

237

useLevelLabels: boolean;

238

```

239

240

**Usage Examples:**

241

242

```javascript

243

const logger = pino();

244

logger.useLevelLabels = true;

245

246

logger.info('Hello world');

247

// Output: {"level":"info","time":1531171074631,"msg":"hello world",...}

248

249

logger.useLevelLabels = false;

250

logger.info('Hello world');

251

// Output: {"level":30,"time":1531171074631,"msg":"hello world",...}

252

```

253

254

### Logger Version

255

256

Access the Pino package version from the logger instance.

257

258

```typescript { .api }

259

/**

260

* Exposes the Pino package version (same as the static pino.version)

261

*/

262

readonly version: string;

263

```

264

265

**Usage Examples:**

266

267

```javascript

268

const logger = pino();

269

console.log(logger.version); // "9.9.2"

270

```

271

272

### Message Prefix

273

274

Get the current message prefix for the logger instance.

275

276

```typescript { .api }

277

/**

278

* Get the message prefix that will be prepended to all log messages

279

* Set via the msgPrefix option during logger creation or child logger creation

280

*/

281

readonly msgPrefix: string | undefined;

282

```

283

284

**Usage Examples:**

285

286

```javascript

287

const logger = pino({ msgPrefix: '[APP] ' });

288

console.log(logger.msgPrefix); // "[APP] "

289

290

const childLogger = logger.child({}, { msgPrefix: '[WORKER] ' });

291

console.log(childLogger.msgPrefix); // "[WORKER] "

292

```

293

294

## Format Specifiers

295

296

Pino supports Node.js util.format() style format specifiers in log messages:

297

298

- `%s` - String

299

- `%d` - Number (integer or floating point)

300

- `%j` - JSON (calls JSON.stringify)

301

- `%o` - Object (Node.js object inspection)

302

- `%O` - Object (Node.js object inspection with options)

303

- `%%` - Literal percent sign

304

305

**Usage Examples:**

306

307

```javascript

308

logger.info('User %s has %d points', username, points);

309

logger.debug('Request body: %j', requestBody);

310

logger.error('Error occurred at %s: %o', new Date().toISOString(), errorObj);

311

```

312

313

## Log Output Format

314

315

All log methods produce structured JSON output with consistent fields:

316

317

```json

318

{

319

"level": 30,

320

"time": 1531171074631,

321

"msg": "hello world",

322

"pid": 657,

323

"hostname": "server-01"

324

}

325

```

326

327

Additional fields from the object parameter are merged into the log record:

328

329

```json

330

{

331

"level": 50,

332

"time": 1531171074631,

333

"msg": "Request failed",

334

"pid": 657,

335

"hostname": "server-01",

336

"userId": 123,

337

"requestId": "abc-def-456",

338

"statusCode": 500

339

}

340

```