Skip to content

Commit 0a027a6

Browse files
authored
feat: add configurable log levels via LOG_LEVEL env var (#92)
1 parent 23e0946 commit 0a027a6

File tree

32 files changed

+105
-70
lines changed

32 files changed

+105
-70
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,34 @@ npm install appium-ios-remotexpc
4242
- **Pair Record Management**: Read and write device pairing records.
4343
- **Packet Streaming**: Stream packets between host and device for service communication.
4444

45+
## Configuration
46+
47+
### Environment Variables
48+
49+
#### APPIUM_IOS_REMOTEXPC_LOG_LEVEL
50+
51+
Controls the logging verbosity of the library.
52+
53+
- **Default**: `info`
54+
- **Possible values**: Standard log levels supported by @appium/support logger
55+
- `silly` - Most verbose, logs everything
56+
- `verbose` - Very detailed logs
57+
- `debug` - Detailed debugging information
58+
- `info` - General informational messages (default)
59+
- `warn` - Warning messages
60+
- `error` - Error messages only
61+
- **Usage**:
62+
63+
```bash
64+
# Set log level to debug for verbose output
65+
APPIUM_IOS_REMOTEXPC_LOG_LEVEL=debug npm test
66+
67+
# Set log level to error for minimal output
68+
APPIUM_IOS_REMOTEXPC_LOG_LEVEL=error node your-script.js
69+
```
70+
71+
This is particularly useful for debugging issues or reducing log noise in production environments.
72+
4573
## Architecture Flow
4674

4775
The following diagram illustrates the high-level flow of how the tunnel is created:

src/lib/apple-tv/encryption/chacha20-poly1305.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { logger } from '@appium/support';
21
import { createCipheriv, createDecipheriv } from 'node:crypto';
32

3+
import { getLogger } from '../../logger.js';
44
import { CryptographyError } from '../errors.js';
55

6-
const log = logger.getLogger('ChaCha20Poly1305');
6+
const log = getLogger('ChaCha20Poly1305');
77

88
export interface ChaCha20Poly1305Params {
99
plaintext?: Buffer;

src/lib/apple-tv/encryption/ed25519.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { logger } from '@appium/support';
21
import {
32
type KeyPairKeyObjectResult,
43
generateKeyPairSync,
54
sign,
65
} from 'node:crypto';
76

7+
import { getLogger } from '../../logger.js';
88
import { CryptographyError } from '../errors.js';
99
import type { PairingKeys } from '../types.js';
1010

11-
const log = logger.getLogger('Ed25519');
11+
const log = getLogger('Ed25519');
1212

1313
const ED25519_PUBLIC_KEY_LENGTH = 32;
1414
const ED25519_PRIVATE_KEY_LENGTH = 32;

src/lib/apple-tv/encryption/hkdf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { logger } from '@appium/support';
21
import { createHmac } from 'node:crypto';
32

3+
import { getLogger } from '../../logger.js';
44
import { HKDF_HASH_ALGORITHM, HKDF_HASH_LENGTH } from '../constants.js';
55
import { CryptographyError } from '../errors.js';
66

7-
const log = logger.getLogger('HKDF');
7+
const log = getLogger('HKDF');
88

99
export interface HKDFParams {
1010
ikm: Buffer;

src/lib/apple-tv/srp/srp-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { logger } from '@appium/support';
21
import { randomBytes } from 'node:crypto';
32

3+
import { getLogger } from '../../logger.js';
44
import {
55
SRP_GENERATOR,
66
SRP_KEY_LENGTH_BYTES,
@@ -22,7 +22,7 @@ import {
2222
hash,
2323
} from './crypto-utils.js';
2424

25-
const log = logger.getLogger('SRPClient');
25+
const log = getLogger('SRPClient');
2626

2727
/**
2828
* SRP (Secure Remote Password) client implementation following RFC 5054.

src/lib/bonjour/bonjour-discovery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { logger } from '@appium/support';
21
import { type ChildProcess, spawn } from 'node:child_process';
32
import { lookup } from 'node:dns/promises';
43
import { EventEmitter } from 'node:events';
54
import { clearTimeout, setTimeout } from 'node:timers';
65
import { setTimeout as delay } from 'node:timers/promises';
76

7+
import { getLogger } from '../logger.js';
88
import {
99
BONJOUR_DEFAULT_DOMAIN,
1010
BONJOUR_SERVICE_TYPES,
@@ -14,7 +14,7 @@ import {
1414
DNS_SD_PATTERNS,
1515
} from './constants.js';
1616

17-
const log = logger.getLogger('BonjourDiscovery');
17+
const log = getLogger('BonjourDiscovery');
1818

1919
const DNS_SD_COMMAND = 'dns-sd';
2020

src/lib/lockdown/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { logger } from '@appium/support';
21
import { Socket } from 'node:net';
32
import tls, { type ConnectionOptions, TLSSocket } from 'tls';
43

54
import { BasePlistService } from '../../base-plist-service.js';
5+
import { getLogger } from '../logger.js';
66
import { type PairRecord } from '../pair-record/index.js';
77
import { PlistService } from '../plist/plist-service.js';
88
import type { PlistMessage, PlistValue } from '../types.js';
99
import { RelayService, createUsbmux } from '../usbmux/index.js';
1010

11-
const log = logger.getLogger('Lockdown');
11+
const log = getLogger('Lockdown');
1212

1313
// Constants
1414
const LABEL = 'appium-internal';
@@ -86,7 +86,7 @@ class DeviceNotFoundError extends Error {
8686

8787
// TLS Manager for handling TLS operations
8888
class TLSManager {
89-
private readonly log = logger.getLogger('TLSManager');
89+
private readonly log = getLogger('TLSManager');
9090

9191
/**
9292
* Upgrades a socket to TLS
@@ -127,7 +127,7 @@ class TLSManager {
127127

128128
// Device Manager for handling device operations
129129
class DeviceManager {
130-
private readonly log = logger.getLogger('DeviceManager');
130+
private readonly log = getLogger('DeviceManager');
131131

132132
/**
133133
* Lists all connected devices

src/lib/logger.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { logger } from '@appium/support';
2+
3+
const LOG_LEVEL = (process.env.APPIUM_IOS_REMOTEXPC_LOG_LEVEL || 'info') as any;
4+
5+
export function getLogger(name: string) {
6+
const log = logger.getLogger(name);
7+
log.level = LOG_LEVEL;
8+
return log;
9+
}

src/lib/pair-record/pair-record.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { logger } from '@appium/support';
21
import fs from 'fs';
32
import path from 'path';
43

5-
const log = logger.getLogger('PairRecord');
4+
import { getLogger } from '../logger.js';
5+
6+
const log = getLogger('PairRecord');
67

78
/**
89
* Interface defining the structure of a pair record.

src/lib/plist/binary-plist-parser.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
* This module provides functionality to parse binary property lists (bplists)
55
* commonly used in Apple's iOS and macOS systems.
66
*/
7-
import { logger } from '@appium/support';
8-
7+
import { getLogger } from '../logger.js';
98
import type { PlistArray, PlistDictionary, PlistValue } from '../types.js';
109
import {
1110
APPLE_EPOCH_OFFSET,
@@ -14,7 +13,7 @@ import {
1413
BPLIST_TYPE,
1514
} from './constants.js';
1615

17-
const log = logger.getLogger('Plist');
16+
const log = getLogger('Plist');
1817

1918
/**
2019
* Represents a temporary object during binary plist parsing

0 commit comments

Comments
 (0)