Skip to content

feat: upgrade logger #1265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: feat/upgrade-logger
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import Config
# Do not print debug messages in production
config :logger, level: :info

# Add the CloudWatch logger backend in production
config :logger, backends: [:console, {Cadet.Logger.CloudWatchLogger, :cloudwatch_logger}]

# Configure CloudWatch Logger
config :logger, :cloudwatch_logger,
level: :info,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id],
log_group: "cadet-logs",
log_stream: "#{node()}-#{:os.system_time(:second)}"

# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ config :cadet, CadetWeb.Endpoint,
config :cadet, environment: :test

# Print only warnings and errors during test
config :logger, level: :warn, compile_time_purge_matching: [[level_lower_than: :warn]]
config :logger, level: :warning, compile_time_purge_matching: [[level_lower_than: :warning]]

config :ex_aws,
access_key_id: "hello",
Expand Down
24 changes: 20 additions & 4 deletions lib/cadet/accounts/teams.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ defmodule Cadet.Accounts.Teams do
alias Cadet.Accounts.{Team, TeamMember, Notification}
alias Cadet.Assessments.{Answer, Submission}

@doc """
Returns all teams for a given course.

## Parameters

* `course_id` - The ID of the course.

## Returns

Returns a list of teams.

"""
def all_teams_for_course(course_id) do
Team
|> join(:inner, [t], a in assoc(t, :assessment))
|> where([t, a], a.course_id == ^course_id)
|> Repo.all()
|> Repo.preload(assessment: [:config], team_members: [student: [:user]])
end

@doc """
Creates a new team and assigns an assessment and team members to it.

Expand Down Expand Up @@ -44,8 +64,6 @@ defmodule Cadet.Accounts.Teams do

true ->
Enum.reduce_while(attrs["student_ids"], {:ok, nil}, fn team_attrs, {:ok, _} ->
student_ids = Enum.map(team_attrs, &Map.get(&1, "userId"))

{:ok, team} =
%Team{}
|> Team.changeset(attrs)
Expand Down Expand Up @@ -85,7 +103,6 @@ defmodule Cadet.Accounts.Teams do
ids = Enum.map(team, &Map.get(&1, "userId"))

unique_ids_count = ids |> Enum.uniq() |> Enum.count()
all_ids_distinct = unique_ids_count == Enum.count(ids)

student_already_in_team?(-1, ids, assessment_id)
end)
Expand Down Expand Up @@ -209,7 +226,6 @@ defmodule Cadet.Accounts.Teams do

"""
def update_team(team = %Team{}, new_assessment_id, student_ids) do
old_assessment_id = team.assessment_id
team_id = team.id
new_student_ids = Enum.map(hd(student_ids), fn student -> Map.get(student, "userId") end)

Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/devices/devices.ex
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ defmodule Cadet.Devices do
},
300,
[],
''
""
)

# ExAws includes the session token in the signed payload and doesn't allow
Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/jobs/autograder/lambda_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Cadet.Autograder.LambdaWorker do
lambda_params = build_request_params(params)

if Enum.empty?(lambda_params.testcases) do
Logger.warn("No testcases found. Skipping autograding for answer_id: #{answer.id}")
Logger.warning("No testcases found. Skipping autograding for answer_id: #{answer.id}")
# Fix for https://github.com/source-academy/backend/issues/472
Process.sleep(1000)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/jobs/xml_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule Cadet.Updater.XMLParser do
:ok
else
{:error, stage, %{errors: [assessment: {"has submissions", []}]}, _} when is_atom(stage) ->
Logger.warn("Assessment has submissions, ignoring...")
Logger.warning("Assessment has submissions, ignoring...")
{:ok, "Assessment has submissions, ignoring..."}

{:error, error_message} ->
Expand Down
Loading
Loading