Add granular logging across all source files

Introduce logger infrastructure and add structured logging to every layer:
alpaca.ts (buy/sell/quote/clock), momentum-indicator.ts (evaluate flow),
momentum-strategy.ts (poll loop), index.ts (startup/cycle), and trading.ts
(market timing). Replace raw console.log calls with leveled logger. Update
all tests with appropriate console spies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jon
2026-02-09 17:00:15 -07:00
parent 075572a01c
commit 188a1dc8b0
13 changed files with 91 additions and 19 deletions

View File

@@ -29,7 +29,7 @@ afterEach(() => {
describe('printAsset', () => {
beforeEach(() => {
vi.spyOn(console, 'log').mockImplementation(() => {});
vi.spyOn(console, 'debug').mockImplementation(() => {});
});
it('logs fractional when asset is fractionable', async () => {
@@ -38,7 +38,7 @@ describe('printAsset', () => {
});
await printAsset(alpaca, 'TQQQ');
expect(console.log).toHaveBeenCalledWith('TQQQ is fractional');
expect(console.debug).toHaveBeenCalledWith(expect.stringContaining('[DEBUG]'), 'TQQQ is fractional');
});
it('logs not fractional when asset is not fractionable', async () => {
@@ -47,7 +47,7 @@ describe('printAsset', () => {
});
await printAsset(alpaca, 'BRK.A');
expect(console.log).toHaveBeenCalledWith('BRK.A is not fractional');
expect(console.debug).toHaveBeenCalledWith(expect.stringContaining('[DEBUG]'), 'BRK.A is not fractional');
});
});
@@ -63,6 +63,11 @@ describe('accountBalance', () => {
});
describe('waitForNextOpen', () => {
beforeEach(() => {
vi.spyOn(console, 'log').mockImplementation(() => {});
vi.spyOn(console, 'debug').mockImplementation(() => {});
});
it('calls getClock and waits until next_open', async () => {
const futureDate = new Date(Date.now() + 60000).toISOString();
const alpaca = mockAlpaca({