or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

browser-integration.mdconfiguration.mdcore-logging.mdindex.mdreact-native-integration.mdserver-integration.mdtelemetry.md

core-logging.mddocs/

0

# Core Logging

1

2

Core error and message logging functionality providing multiple severity levels with flexible argument patterns and automatic error enrichment.

3

4

## Capabilities

5

6

### Log Method

7

8

General purpose logging method that accepts multiple argument types.

9

10

```typescript { .api }

11

/**

12

* Log a message or error at the 'log' level

13

* @param args - Variable arguments: message, error, object, callback, etc.

14

* @returns Object containing the UUID of the logged item

15

*/

16

function log(...args: LogArgument[]): LogResult;

17

```

18

19

**Usage Examples:**

20

21

```javascript

22

// String message

23

rollbar.log('User action completed');

24

25

// Error object

26

rollbar.log(new Error('Something went wrong'));

27

28

// Message with additional data

29

rollbar.log('User action', { userId: 123, action: 'login' });

30

31

// Message with callback

32

rollbar.log('Processing data', (err, data) => {

33

if (err) console.error('Failed to log:', err);

34

});

35

36

// Multiple arguments

37

rollbar.log('Payment processed', paymentData, user, callback);

38

```

39

40

### Debug Method

41

42

Debug level logging for detailed diagnostic information.

43

44

```typescript { .api }

45

/**

46

* Log a message or error at the 'debug' level

47

* @param args - Variable arguments: message, error, object, callback, etc.

48

* @returns Object containing the UUID of the logged item

49

*/

50

function debug(...args: LogArgument[]): LogResult;

51

```

52

53

### Info Method

54

55

Informational logging for general application events.

56

57

```typescript { .api }

58

/**

59

* Log a message or error at the 'info' level

60

* @param args - Variable arguments: message, error, object, callback, etc.

61

* @returns Object containing the UUID of the logged item

62

*/

63

function info(...args: LogArgument[]): LogResult;

64

```

65

66

### Warn Method

67

68

Warning level logging for potential issues that don't stop execution.

69

70

```typescript { .api }

71

/**

72

* Log a message or error at the 'warning' level

73

* @param args - Variable arguments: message, error, object, callback, etc.

74

* @returns Object containing the UUID of the logged item

75

*/

76

function warn(...args: LogArgument[]): LogResult;

77

```

78

79

### Warning Method

80

81

Alias for the warn method.

82

83

```typescript { .api }

84

/**

85

* Log a message or error at the 'warning' level (alias for warn)

86

* @param args - Variable arguments: message, error, object, callback, etc.

87

* @returns Object containing the UUID of the logged item

88

*/

89

function warning(...args: LogArgument[]): LogResult;

90

```

91

92

### Error Method

93

94

Error level logging for exceptions and failures.

95

96

```typescript { .api }

97

/**

98

* Log a message or error at the 'error' level

99

* @param args - Variable arguments: message, error, object, callback, etc.

100

* @returns Object containing the UUID of the logged item

101

*/

102

function error(...args: LogArgument[]): LogResult;

103

```

104

105

**Usage Examples:**

106

107

```javascript

108

// Log caught exception

109

try {

110

riskyOperation();

111

} catch (err) {

112

rollbar.error(err);

113

}

114

115

// Log error with context

116

rollbar.error('Database connection failed', {

117

host: 'db.example.com',

118

port: 5432,

119

retries: 3

120

});

121

```

122

123

### Critical Method

124

125

Critical level logging for severe errors requiring immediate attention.

126

127

```typescript { .api }

128

/**

129

* Log a message or error at the 'critical' level

130

* @param args - Variable arguments: message, error, object, callback, etc.

131

* @returns Object containing the UUID of the logged item

132

*/

133

function critical(...args: LogArgument[]): LogResult;

134

```

135

136

### Wait Method

137

138

Wait for all pending items to be sent before executing callback.

139

140

```typescript { .api }

141

/**

142

* Wait for all pending items to be sent to Rollbar

143

* @param callback - Function to call when all items are sent

144

*/

145

function wait(callback: () => void): void;

146

```

147

148

**Usage Example:**

149

150

```javascript

151

// Ensure all logs are sent before shutting down

152

rollbar.error('Critical system error');

153

rollbar.wait(() => {

154

console.log('All logs sent, shutting down...');

155

process.exit(1);

156

});

157

```

158

159

### Last Error Method

160

161

Get the last error that occurred in Rollbar itself.

162

163

```typescript { .api }

164

/**

165

* Get the last error that occurred within Rollbar

166

* @returns The last error or null if no errors

167

*/

168

function lastError(): MaybeError;

169

```

170

171

### Build JSON Payload

172

173

Build a JSON payload from item data for manual sending.

174

175

```typescript { .api }

176

/**

177

* Build JSON payload from item data

178

* @param item - Item data to convert to JSON

179

* @returns JSON string representation of the item

180

*/

181

function buildJsonPayload(item: any): string;

182

```

183

184

### Send JSON Payload

185

186

Send a pre-built JSON payload to Rollbar.

187

188

```typescript { .api }

189

/**

190

* Send a pre-built JSON payload to Rollbar

191

* @param jsonPayload - JSON string to send

192

*/

193

function sendJsonPayload(jsonPayload: string): void;

194

```

195

196

## Types

197

198

```typescript { .api }

199

type LogArgument = string | Error | object | Dictionary | Callback | Date | any[] | undefined;

200

201

interface LogResult {

202

uuid: string;

203

}

204

205

type MaybeError = Error | undefined | null;

206

207

type Level = 'debug' | 'info' | 'warning' | 'error' | 'critical';

208

209

interface Callback<TResponse = any> {

210

(err: MaybeError, response: TResponse): void;

211

}

212

213

type Dictionary = { [key: string]: unknown };

214

```

215

216

## Argument Patterns

217

218

The logging methods accept flexible argument patterns:

219

220

1. **Message only**: `rollbar.error('Something happened')`

221

2. **Error only**: `rollbar.error(new Error('Failed'))`

222

3. **Message + Error**: `rollbar.error('Operation failed', error)`

223

4. **Message + Data**: `rollbar.error('Failed to process', { userId: 123 })`

224

5. **Message + Data + Callback**: `rollbar.error('Failed', data, callback)`

225

6. **Error + Data**: `rollbar.error(error, { context: 'payment' })`

226

7. **Multiple mixed arguments**: `rollbar.error('Payment failed', error, userData, callback)`

227

228

The library automatically determines the appropriate handling based on argument types.