Disable Elixir Ecto Debug output - debugging

Whatever in iex> or using mix run -e "My.code" when I run the mix project using ecto, the Ecto's Debugging Mechanism display a bunch of SQLs like below
16:42:12.870 [debug] SELECT a0.`id` FROM `account` AS a0 WHERE (a0.`account_name` = ?) ["71000000313"] (39.6ms)`
...
When I dont need the debug output anymore, How can I turn it off, I cannot find anything about how to change ecto log level stuff.
Thanks in advance.

If you want to change the Ecto (pre 2.0) log level (and only it) then you can use the log_level configuration option that can be set in your applications Ecto repository configuration.
In example:
config :my_app, MyApp.Repo,
adapter: Ecto.Adapters.Postgres,
database: "my_app",
username: "my_app",
password: "secret",
hostname: "localhost",
port: 5433,
log_level: :info
Of course beside the above you can always change the Logger configuration log level option if you want to change the overall log level (not only the Ecto log level) e.g.:
config :logger, level: :info
Update (by #Milos):
Since Ecto 2.0.0, instead of log_level: :info you need to use loggers: [{Ecto.LogEntry, :log, [:info]}].
Update (by #AndyMacKinlay):
Since Ecto 3.0.0, instead of log_level: :info you need to use log: :info.
Update (by #Simon):
Since Ecto 3.0.0, you can also completely disable logging log: false.

Your logging level is configured in your config/#{env}.exs files. If you look into config/prod.exs it most likely already has that level set to :info:
config :logger, level: :info
So if you run the app with MIX_ENV=prod iex -S mix you won't get the debug output. This means that when you build a release with something like MIX_ENV=prod mix release the resulting build won't be producing this output. Alternatively you may set level: :info or :warn for whatever environment you want by changing the appropriate config/#{env}.exs.

Ecto 3 answer to completely disabling logging would be:
config :app, App.Repo,
username: "postgres",
password: "postgres",
database: "app_dev",
log: false

To disable debug messages temporarily you can do Logger.configure(level: :warn) and then re-enable with Logger.configure(level: :debug).
https://hexdocs.pm/logger/Logger.html#Levels

Simple put loggers: [] in
config :my_app, MyApp.Repo,
adapter: Ecto.Adapters.Postgres,
database: "my_app_repo",
username: "DB_USERNAME",
password: "DB_PASSWORD",
hostname: "DB_HOST",
loggers: []

Related

Set logfile location based on OS in spring boot application.properties/.yml

I'm wondering if there's a nice clean way to set logging location based on OS just using the application.properties file in Spring Boot?
For instance is it possible to use a regex matcher on ${os.name} or would I just need to go ahead and create a groovy script or something?
My ideal solution is something like
logging:
file: ${os.name}.test(/*window*/gi) ? C:/ProgramData/Logs/ : /var/log/
You can take advantage of spring profiles and pick configurations according to the -Dspring.profile.active=some_profile system property or SPRING_PROFILES_ACTIVE=some_profile env variable.
Yaml file could be
# a safe default relative to app root
logging:
file: logs
----
spring:
profiles: nix
logging:
file: /var/log/myapp
----
spring:
profiles: win
logging:
file: C:/ProgramData/Logs/
App is executed as
java -Dspring.profile.active=nix <more opts> MyAppMain
or also:
SPRING_PROFILES_ACTIVE=nix java <more opts> MyAppMAin

Phoenix framework - assets don't update without running mix phx.digest

After changing an asset (a css or js) file I see in the logs that the change was noticed and compiled, and the browser also auto-reloads.
[debug] Live reload: priv/static/js/app.js
10:53:15 - info: compiled MyComponent.jsx and 2095 cached files into 2
files in 2.3 sec
However, it doesn't appear that the assets in /priv/static were actually updated. I can only see my change in the browser once I run mix phx.digest, and hard refresh the browser.
Any ideas on how to troubleshoot this?
Using:
Phoenix 1.3
brunch 2.10.7
config/dev.exs:
config :my_app, MyApp.Web.Endpoint,
http: [port: 4000],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
cd: Path.expand("../assets", __DIR__)]]
# Watch static and templates for browser reloading.
config :my_app, MyApp.Web.Endpoint,
live_reload: [
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r{priv/gettext/.*(po)$},
~r{lib/my_app/web/views/.*(ex)$},
~r{lib/my_app/web/templates/.*(eex)$}
]
]
TL;DR — If you don't set the cache_static_manifest setting on your endpoint, it won't generate versioned URLs.
So, I know I'm about three years late here, but I recently figured this out. I discovered that merely setting the cache_static_manifest value in the Endpoint config will cause it to use the digest in any mode. (This is documented, but not in a way that seemed particularly clear to me.)
Now, you might be thinking "But I didn't set that in dev mode." I thought that, too, until I realized that I had written a naive config/runtime.exs.
At the time, I had been focused on configuring things a runtime when running a release, but completely forgot that it configures things even when not running in a release. Once I made it conditional, everything was fine.
Example:
if Config.config_env == :production do
config :my_app, MyAppWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
end
I ran into the same issue and for me it helped to manually remove the static folder with rm -rf priv/static and to restart the server with mix phx.server. Afterwards the hot reloading worked without having to manually run mix phx.digest all the time.
Another possible cause is that the Endpoint module (lib/my_app_web/endpoint.ex) is setting Plug.Static to use compressed assets:
defmodule MyAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app_web
plug Plug.Static,
# ...
gzip: true,
Then, if a release has been built from within the project directory and the gzipped assets are still present when developing, they will be served instead of the newly-saved, non-compressed assets.
To avoid this:
config/dev.exs:
config :my_app, :environment, :dev
config/test.exs:
config :my_app, :environment, :test
config/prod.exs:
config :my_app, :environment, :prod
lib/my_app_web/endpoint.ex:
defmodule MyAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app_web
in_prod = Application.get_env(:my_app, :environment) == :prod
plug Plug.Static,
# ...
gzip: in_prod,

Ruby Sinatra/Postgres - can't connect to heroku database with PG.connect?

I am trying to get a site set up on Heroku using Sinatra and PostgreSQL. It worked locally (connecting to local database), but after pushing it to Heroku and changing my PG.connect to reflect that, I get an Internal Server Error the moment a page tries to access the database.
require 'uri'
require 'pg'
uri = URI.parse(ENV['DATABASE_URL'])
def db(uri)
begin
connection = PG.connect(uri.hostname, uri.port, nil, nil, uri.path[1..-1], uri.user, uri.password)
yield(connection)
ensure
connection.close
end
end
I am pretty sure these are parsing correctly, because ENV['DATABASE_URL'] displays the full postgres://user:password#host:port/database information that I'm expecting, and if I do the same in IRB uri.hostname, ui.port, etc all return what's expected .
This is my first time trying to get a site working on Heroku, so I am not even sure how to troubleshoot this. (And I googled for about all of yesterday.)
Results for heroku pg:
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 9.4.2
Created: 2015-05-30 19:24 UTC
Data Size: 17.7 MB
Tables: 5
Rows: 9320/10000 (In compliance, close to row limit)
Fork/Follow: Unsupported
Rollback: Unsupported
And all the tables show up when when I do heroku pg:psql <database> from the cli.
Some answers I've seen said to add database.yml to my root app directory, so:
production:
adapter: 'postgresql'
database: '<database>'
host: ENV['DATABASE_URL']
username: '<username>'
There's probably something simple I'm missing, but I haven't seen a complete guide for Sinatra/PSQL on Heroku - nothing that goes specifically into setting up and connecting to your database. (Everything seems Rails-related.)
In your database.yml file you need to specify the correct host for the host entry. You are passing what is stored in DATABASE_URL (something like postgres://user:password#host:port/database) but it should just be the host.
You will also need to specify a port if it isn't the default for PostgreSQL.
Edit: should also point out if you plan to store the host (or anything else - you definitely should for username and password) in an environment variable you'll need to wrap it, e.g. <%= ENV['HOST'] %>, not just ENV['HOST'] (i.e. how you have in the database.yml excerpt above)

I want to use ActiveRecord in a non Rails way. How can I get my code to put the db file in the right directory?

config/database.yml
default: &default
adapter: sqlite3
encoding: unicode
development:
<<: *default
database: development.sqlite3
username: admin
password: wsxqaz
server: localhost
# port:
ruby code:
require "yaml"
require "active_record"
# shorten lines with this namespace
include ActiveRecord::Tasks
# trying to use db folder
DatabaseTasks.db_dir = './db'
db_config_file = "./config/database.yml"
db_config = YAML.load_file(db_config_file)
db_type = db_config['development']
#sldbtask = SQLiteDatabaseTasks.new(db_type, root = './')
#sldbtask.create
I've tried changing the root argument but that doesn't make any difference either.
What do I need to get my db file into the db directory? It creates it okay and the table stuff is pending. First things first.
I believe that the database is supposed to be generated in the root directory. The db folder is used for activerecord's schema and migration files. Why is it so important that the database generates in the db directory?
EDIT
I just found an easier way to do this. After you require all of the files you want, then enter set :database, {database:"./db/myDatabase.db"}. If you already have the line set :database in your code, just add that to it. Good luck!

why am I getting an empty test suite with parallel_tests ruby gem

Any help getting the gem working would be appreciated. I'm down to configuration issues (i think) and there isn't a lot of documentation to help me get running.
So I have the parallel_tests gem in my project. I believe I have two problems, one that cannot be seen without the other.
The first problem is that I don't think I have my database.yml file setup correctly. #1 we call it servers.yml (not sure if there is an importance with the name), and 2 we didn't have a "test" section setup. The example shows
test:
database: yourproject_test<%= ENV['TEST_ENV_NUMBER'] %>
our server.yml file contains the following:
db1:
adapter: jdbc
driver: oracle.jdbc.driver.OracleDriver
url: url_to_db1
username: uname
password: pass
db2:
adapter: jdbc
driver: oracle.jdbc.driver.OracleDriver
url: url_to_db2
username: uname
password: pass
db3:
adapter: jdbc
driver: oracle.jdbc.driver.OracleDriver
url: url_to_db3
username: uname
password: pass
so I just added the test line above the rest of the databases at the top of the file
The problem is I cannot even check to see if that's working right because when I try to run the parallel_tests gems, it returns empty!!!!
This is the guide I've been following, with the exception of finding out I had to require parallel_tests/tasks into my rakefile: https://github.com/grosser/parallel_tests
I have require 'parallel_tests/tasks' in my rakefile
I run the 3 commands in the parallel_tests gem to get execution running (don't worry about the java options and java tool options)
As you can see, there are no error messages, nothing out of the ordenary other then my tests do not run with or without the parameters to the features task. The following is a printout of the trace stack
Was running this on a windows machine... Windows doesn't support forking which is what this gem does.
Update, the newer versions of the gem allow you to run on any platform, with a new command. parallel_cucumber is the new command. Check https://github.com/grosser/parallel_tests for more details

Resources