Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cloud_controller/runners/puma_runner.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'puma'
require 'puma/configuration'
require 'puma/events'
require 'cloud_controller/logs/steno_io'
require 'steno/steno'
require 'cloud_controller/execution_context'

module VCAP::CloudController
Expand Down Expand Up @@ -51,7 +51,7 @@ def initialize(config, app, logger, periodic_updater, request_logs)
conf.before_worker_shutdown { request_logs.log_incomplete_requests if request_logs }
end

log_writer = Puma::LogWriter.new(StenoIO.new(logger, :info), StenoIO.new(logger, :error))
log_writer = Puma::LogWriter.new(Steno::LoggerIO.new(logger, :info), Steno::LoggerIO.new(logger, :error))

events = Puma::Events.new
events.after_booted { @periodic_updater.setup_updates }
Expand Down
22 changes: 16 additions & 6 deletions lib/steno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This is a **modified version** of the original Steno library, adapted for CCNG's
- Custom RFC3339 codec (previously in `lib/steno_custom_codec_temp/`)
- LICENSE file (Apache 2.0 - for attribution)
- NOTICE file (Apache 2.0 copyright notices)
- Test suite (in `spec/unit/lib/steno/`)
- Test suite (in `spec/isolated_specs/steno/`)

## What Was Excluded

Expand Down Expand Up @@ -66,7 +66,7 @@ Syslog.close if Syslog.opened?
- Required adding `require 'active_support/core_ext/module/delegation'`

### 4. Test Structure Updates
- Moved tests from `lib/steno/spec/` to `spec/unit/lib/steno/` (CCNG convention)
- Moved tests from `lib/steno/spec/` to `spec/isolated_specs/steno/` (CCNG convention)
- Removed global spec_helper requires, added explicit requires per test
- Wrapped test describes in parent `RSpec.describe` blocks

Expand All @@ -75,7 +75,7 @@ Syslog.close if Syslog.opened?

**Removed**:
- `lib/steno/sink/eventlog.rb` (Windows Event Log sink)
- `spec/unit/lib/steno/unit/sink/eventlog_spec.rb`
- `spec/isolated_specs/steno/unit/sink/eventlog_spec.rb`
- Windows conditionals from config.rb, syslog.rb, test files
- `WINDOWS` constant from sink/base.rb

Expand All @@ -86,8 +86,8 @@ Syslog.close if Syslog.opened?
- `lib/steno/version.rb` - Version constant no longer needed (not a gem)
- `lib/steno/json_prettifier.rb` - CLI tool for prettifying logs, unused (~110 lines)
- `lib/steno/core_ext.rb` - Monkey patches for `.logger` on Module/Class/Object, CCNG uses `Steno.logger()` instead (~50 lines)
- `spec/unit/lib/steno/unit/json_prettifier_spec.rb` - Tests for removed feature
- `spec/unit/lib/steno/unit/core_ext_spec.rb` - Tests for removed feature
- `spec/isolated_specs/steno/unit/json_prettifier_spec.rb` - Tests for removed feature
- `spec/isolated_specs/steno/unit/core_ext_spec.rb` - Tests for removed feature
- Removed `require 'steno/version'` from steno.rb

**What's kept** (even if unused):
Expand Down Expand Up @@ -120,6 +120,16 @@ Syslog.close if Syslog.opened?
- `Steno::Context::Null` - Default fallback context
- All log levels including debug1, debug2 - debug2 is actively used

### 8. LoggerIO Adapter for Puma Integration
**Rationale**: `Puma::LogWriter` requires IO-compatible objects. Previously, a `StenoIO` class existed outside the Steno library to bridge this gap. Since Steno is now inlined, the adapter was moved into the Steno namespace for consistency.

**Added**:
- `lib/steno/logger_io.rb`: `Steno::LoggerIO` - an IO adapter that wraps a `Steno::Logger` and forwards `write`/`puts` calls to it at a configured log level. Used by `PumaRunner` to pass Steno loggers as IO objects to `Puma::LogWriter`.
- `spec/isolated_specs/steno/unit/logger_io_spec.rb`: Tests for `Steno::LoggerIO`.

**Modified**:
- `lib/steno/logger.rb`: Broadened the callstack filter from removing only frames from `logger.rb` to removing all frames within `lib/steno/`. This ensures that log records originating via `Steno::LoggerIO` correctly attribute the source location to the caller rather than to the adapter itself.

---

## Making Future Modifications
Expand All @@ -129,7 +139,7 @@ If you modify this integrated steno library:
1. **Document changes** in the "Modifications Made After Integration" section above
2. **Include rationale** for why the change was made
3. **List affected files** and what changed
4. **Run tests** to ensure nothing breaks: `bundle exec rspec spec/unit/lib/steno/`
4. **Run tests** to ensure nothing breaks: `bundle exec rspec spec/isolated_specs/steno/`
5. **Update this README** in the same commit as your changes

## Original Steno Commit History (102 commits)
Expand Down
18 changes: 4 additions & 14 deletions lib/steno/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,11 @@ def log(level_name, message=nil, user_data=nil)
private

def parse_record_loc(callstack)
file = nil
lineno = nil
method = nil
frame = callstack.find { |f| f !~ %r{/lib/steno/} } || callstack.last

callstack.each do |frame|
next if frame =~ /logger\.rb/

file, lineno, method = frame.split(':')

lineno = lineno.to_i

method = ::Regexp.last_match(1) if method =~ /in `([^']+)/

break
end
file, lineno, method = frame.split(':')
lineno = lineno.to_i
method = ::Regexp.last_match(1) if method =~ /in `([^`']+)/

[file, lineno, method]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class StenoIO
module Steno
end

class Steno::LoggerIO
def initialize(logger, level)
@logger = logger
@level = level
Expand Down
1 change: 1 addition & 0 deletions lib/steno/steno.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'steno/context'
require 'steno/errors'
require 'steno/log_level'
require 'steno/logger_io'
require 'steno/logger'
require 'steno/record'
require 'steno/sink'
Expand Down
34 changes: 34 additions & 0 deletions spec/isolated_specs/steno/unit/logger_io_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'steno/steno'

RSpec.describe Steno::LoggerIO do
let(:logger) { double(:logger) }
let(:level) { :info }
let(:logger_io) { described_class.new(logger, level) }

describe '#write' do
it 'writes to the logger' do
expect(logger).to receive(:log).with(level, 'message')

logger_io.write('message')
end
end

describe '#sync' do
it 'returns true' do
expect(logger_io.sync).to be(true)
end
end

context 'when writing a record' do
let(:logger) { Steno::Logger.new('test', []) }

it 'removes logger_io.rb from the callstack' do
expect(Steno::Record).to receive(:new).and_wrap_original do |original_method, source, log_level, message, loc, data|
expect(loc[0]).not_to match(/logger_io\.rb/)
original_method.call(source, log_level, message, loc, data)
end

logger_io.write('message')
end
end
end
13 changes: 9 additions & 4 deletions spec/isolated_specs/steno/unit/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,18 @@
end

it 'creates a record with the proper level' do
sink = double('sink')
expect(Steno::Record).to receive(:new).with('test', :warn, 'message', anything, anything).and_call_original
allow(sink).to receive(:add_record)

my_logger = described_class.new('test', [sink])
logger.warn('message')
end

it 'creates a record with logger.rb being removed from the callstack' do
expect(Steno::Record).to receive(:new).and_wrap_original do |original_method, source, log_level, message, loc, data|
expect(loc[0]).not_to match(/logger\.rb/)
original_method.call(source, log_level, message, loc, data)
end

my_logger.warn('message')
logger.warn('message')
end
end

Expand Down
24 changes: 0 additions & 24 deletions spec/unit/lib/cloud_controller/logs/steno_io_spec.rb

This file was deleted.