Skip to content

Commit

Permalink
chore: simplify logging
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Jan 13, 2025
1 parent bbfe3dd commit d54fbb9
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 104 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG CRYSTAL_VERSION=latest

FROM placeos/crystal:$CRYSTAL_VERSION as build
FROM placeos/crystal:$CRYSTAL_VERSION AS build
WORKDIR /app

# Set the commit through a build arg
Expand Down
64 changes: 4 additions & 60 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ shards:
git: https://github.com/veelenga/ameba.git
version: 1.6.4

any_hash:
git: https://github.com/sija/any_hash.cr.git
version: 0.2.5

backtracer:
git: https://github.com/sija/backtracer.cr.git
version: 1.2.2
Expand All @@ -37,22 +33,10 @@ shards:
git: https://github.com/kostya/cron_parser.git
version: 0.4.0

csuuid:
git: https://github.com/wyhaines/csuuid.cr.git
version: 1.0.2

db:
git: https://github.com/crystal-lang/crystal-db.git
version: 0.13.1

debug:
git: https://github.com/sija/debug.cr.git
version: 2.0.4

defined:
git: https://github.com/wyhaines/defined.cr.git
version: 0.3.6

email:
git: https://github.com/arcage/crystal-email.git
version: 0.7.1
Expand Down Expand Up @@ -105,10 +89,6 @@ shards:
git: https://github.com/luckyframework/lucky_router.git
version: 0.6.0

nbchannel:
git: https://github.com/wyhaines/nbchannel.cr.git
version: 0.1.0

neuroplastic:
git: https://github.com/spider-gazelle/neuroplastic.git
version: 1.13.1
Expand All @@ -121,26 +101,10 @@ shards:
git: https://github.com/spider-gazelle/openssl_ext.git
version: 2.4.4

opentelemetry-api:
git: https://github.com/wyhaines/opentelemetry-api.cr.git
version: 0.5.2+git.commit.77c9232ca6ff7de52529f309a0cb20b8459f7b20

opentelemetry-instrumentation:
git: https://github.com/wyhaines/opentelemetry-instrumentation.cr.git
version: 0.6.0+git.commit.6978cfe19aa590fb61fd7fdc0a25eb0c78674309

opentelemetry-sdk:
git: https://github.com/wyhaines/opentelemetry-sdk.cr.git
version: 0.6.4+git.commit.c7237732135f6d0cab84abc6bb6d438c9f8f9d66

pars:
git: https://github.com/spider-gazelle/pars.git
version: 1.1.0

parse_date:
git: https://github.com/wyhaines/parsedate.cr.git
version: 0.1.2

pegmatite:
git: https://github.com/jemc/crystal-pegmatite.git
version: 0.2.3+git.commit.f1b6d99b71774f82b6bd17b825d6d7fdd5de38f9
Expand All @@ -163,7 +127,7 @@ shards:

placeos-log-backend:
git: https://github.com/place-labs/log-backend.git
version: 0.11.4
version: 0.13.0

placeos-models:
git: https://github.com/placeos/models.git
Expand All @@ -177,42 +141,22 @@ shards:
git: https://github.com/spider-gazelle/promise.git
version: 3.2.0

protobuf:
git: https://github.com/jeromegn/protobuf.cr.git
version: 2.3.1

raven:
git: https://github.com/sija/raven.cr.git
version: 1.9.4+git.commit.a43f45229d1ee8030f8f07b101cb159896273195

redis:
git: https://github.com/stefanwille/crystal-redis.git
version: 2.9.1

retriable:
git: https://github.com/sija/retriable.cr.git
version: 0.2.5

secrets-env:
git: https://github.com/place-labs/secrets-env.git
version: 1.3.1

splay_tree_map:
git: https://github.com/wyhaines/splay_tree_map.cr.git
version: 0.3.0

time-ext:
git: https://github.com/wyhaines/time-ext.cr.git
version: 1.0.1
tasker:
git: https://github.com/spider-gazelle/tasker.git
version: 2.1.4

timecop:
git: https://github.com/crystal-community/timecop.cr.git
version: 0.5.0

tracer:
git: https://github.com/wyhaines/tracer.cr.git
version: 0.3.2

ulid:
git: https://github.com/place-labs/ulid.git
version: 0.1.2
Expand Down
5 changes: 0 additions & 5 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ dependencies:
promise:
github: spider-gazelle/promise

# Sentry integration
raven:
github: Sija/raven.cr
branch: master

secrets-env:
github: place-labs/secrets-env

Expand Down
2 changes: 0 additions & 2 deletions src/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ require "./controllers/application"
require "./models/*"
require "./controllers/*"
require "placeos-models"
# Add telemetry after application code
require "./telemetry"

alias Tenant = PlaceOS::Model::Tenant
alias Attendee = PlaceOS::Model::Attendee
Expand Down
21 changes: 7 additions & 14 deletions src/logging.cr
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
require "placeos-log-backend"
require "raven"
require "raven/integrations/action-controller"

require "./constants"

# StaffAPI Logging configuration
module App::Logging
::Log.progname = App::NAME
standard_sentry = Raven::LogBackend.new
comprehensive_sentry = Raven::LogBackend.new(capture_all: true)

# Configure Sentry
Raven.configure &.async=(true)

# Logging configuration
log_backend = PlaceOS::LogBackend.log_backend
log_level = App.running_in_production? ? ::Log::Severity::Info : ::Log::Severity::Debug
namespaces = ["action-controller.*", "#{App::NAME}.*", "place_os.*"]

builder = ::Log.builder
builder.bind "*", log_level, log_backend
builder.bind "raven", :warn, log_backend

namespaces = ["action-controller.*", "#{App::NAME}.*", "place_os.*"]
namespaces.each do |namespace|
builder.bind namespace, log_level, log_backend

# Bind raven's backend
builder.bind namespace, :info, standard_sentry
builder.bind namespace, :warn, comprehensive_sentry
end

::Log.setup_from_env(
Expand All @@ -36,4 +23,10 @@ module App::Logging
backend: log_backend,
log_level_env: "LOG_LEVEL",
)

PlaceOS::LogBackend.register_severity_switch_signals(
production: App.running_in_production?,
namespaces: namespaces,
backend: log_backend,
)
end
13 changes: 0 additions & 13 deletions src/staff-api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,6 @@ end
Signal::INT.trap &terminate
Signal::TERM.trap &terminate

# Allow signals to change the log level at run-time
logging = Proc(Signal, Nil).new do |signal|
level = signal.usr1? ? Log::Severity::Debug : Log::Severity::Info
puts " > Log level changed to #{level}"
Log.builder.bind "#{App::NAME}.*", level, App::LOG_BACKEND
signal.ignore
end

# Turn on DEBUG level logging `kill -s USR1 %PID`
# Default production log levels (INFO and above) `kill -s USR2 %PID`
Signal::USR1.trap &logging
Signal::USR2.trap &logging

# Start the server
server.run do
puts "Listening on #{server.print_addresses}"
Expand Down
9 changes: 0 additions & 9 deletions src/telemetry.cr

This file was deleted.

0 comments on commit d54fbb9

Please sign in to comment.