Change the sbt log level on only my machine in perpetuity? - scala

Every time I use sbt the first thing I do is set the log level to Error:
$ sbt
// ... sbt loads
[my_project] $ error
[my_project] $
Several places on SO and elsewhere recommend adding this to either your build.sbt or your sbt.boot.properties:
set logLevel in run := Level.Error
But I'm working in a shared project with many developers and I don't want to change the log level for everyone, just me! I do currently use SBT_OPTS to tailor sbt's memory usage on my machine, and this may potentially be an option but I can't find any guidance on what format to pass options via SBT_OPTS except for Java things like pass -Dkey=val directly to the java runtime and memory parameters like -Xmx8G.
sbt --help indicates that .sbtopts may also be a potential option:
.sbtopts if this file exists in the current directory, its contents
are prepended to the runner args
But as far as I can tell there are no method to specify command-line "runner args" that set the log level to Error, only for setting the log level to debug via --debug.
I'm a little stumped, I've identified at least two potential avenues (SBT_OPTS and .sbtopts) for passing machine-specific customization to sbt, but do either of these support setting the log level to Error? Or is there a third avenue I'm missing, maybe some elusive ~/.sbt, that I could use to set my machine's sbt log level to Error?

Put the following in $HOME/.sbt/1.0/global.sbt
logLevel := Level.Error
All available log level options are:
Error
Warn
Info
Debug
Thanks #maxkar for leading me to this solution

Related

Slick is failing to find config values in reference.conf (i.e., reference.conf is being ignored), in test setup

When attempting to execute a query via Slick (v3.0.3), I am receiving a com.typesafe.config.ConfigException$Missing exception (wrapped in a ExceptionInInitializerError), exclaiming:
No configuration setting found for key 'slick'
Apparently Slick requires a config value for slick.dumpPaths to be present when debug logging is enabled. Ordinarily, a default value will be provided by the reference.conf file that comes stock in Slick's jar-file, but for some reason that file (or that particular key) is not getting picked up, in this case.
In addition, adding an application.conf (which includes the requested config value, slick.dumpPaths) to my application's resource directory (src/main/resources/, by default) and/or to the test resource directory does not help the problem -- the exception still occurs.
It turns out this was (apparently) happening because I was attempting to run the Slick query via SBT's Tests.Setup hook. My hook, in build.sbt, looks something like this:
testOptions in Test += Tests.Setup(loader =>
loader.loadClass("TestSetup").newInstance)
My guess is that SBT has not properly instantiated the classpath at the time this TestSetup class gets instantiated (and when my Slick query tries to execute). Perhaps someone that knows more about SBT's internals can edit this answer to provide more insight, though.

Typesafe config loads wrong configuration

So the problem is really simple and I hope solution will be as well.
So basically I have two configuration files application.conf and dev.conf. I'm passing my config files from command line like that sbt -Dconfig.file=dev.conf.
The problem is when I use ConfigFactory.load from main object(the one which extends App) it loads config I passed via command line(in this case dev.conf), but when I load the config from different object it loads default application.conf.
Can I load somehow config passed from arguments from any object?
When you run your application with the runMain SBT task, then by default SBT won't create a separate JVM for your code. This has several consequences around the application lifecycle, and of course with regard to system properties as well.
In general, your approach should work, as long as your build configuration does not enable forking. However, I think the better approach would be to actually rely on forking and specify the system property explicitly. This is guaranteed to work. To do this, you need to set the fork setting in the run task to true, and then add a JVM command line option:
Compile / run / fork := true,
Compile / run / javaOptions += "-Dconfig.file=dev.conf",
Don't forget to restart SBT after that. You won't need to pass the config.file property to SBT with this approach; rather, it is controlled by the javaOptions setting, as in the example above.

Set the stack size for SBT

I'm running SBT using my specially built Scala. My built Scala Compiler will do a lot of things at runtime, with a lot of function calls, which can be recursive.
So when I run SBT using my built Scala Compiler, stack overflows after a long time. I try to set -J-Xss when starting SBT. But that doesn't work.
I encountered the problem with SBT heap size before. And many posts says setting -J-Xmx when starting SBT won't change the JVM heap size because it is overridden by the default SBT memory options.
How to set heap size for sbt?
Now, I wonder whether -J-Xss can be overridden by default SBT options, just like -J-Xmx being overridden. Or I should simply try to set -J-Xss larger?
There are a number of ways to do this, but it depends what you are trying to achieve. If you want larger heap for running tests for instance, look at the secondary approach undertaken here.
SBT_OPTS
First you can simply set the environment variable SBT_OPTS which SBT will natively look for while loading itself, and this should override any settings that you want to specify.
export SBT_OPTS = "-Xmx1G;-Xms256m;...";
Custom launcher
The other way to achieve the same is to basically create a custom SBT launching script. Have a look at the example here.
For testing
If you want to modify the testing options, you need to use javaOptions in ThisBuild ++= Seq("-Xmx1g", ...). For them to even be run, you always need to have fork in Test := true, which will create a forked JVM for running tests. Without that, the options specified will not be honoured.

Load Different Config File per Task on SBT

I am trying to load different config file per task in sbt, for example I want to be able to run a task like:
sbt devRun
and loads src/main/resources/application.dev.conf while running:
sbt run
will load src/main/resources/application.conf.
As I understand it, we can load different application.conf when running test by putting it on src/test/resource/application.conf, but using different config file for different task (or scope) will need some code on SBT.
I've been trying to google around and usually the suggestion is to use it on run task like:
$ sbt run -Dconfig.resources="application.dev.conf"
But as far as I understand, the above will only load different config on runtime. I have multiple projects with lots of config file. I want to load them dynamically, based on scope / task. What's the best way to do this?
Thanks before.
You can(must) use the javaOptions setting. It represents Java options when sbt runs a forked JVM, e.g. it runs tests in a different JVM process(by default).
javaOptions in Test += "-Dconfig.resource=" + System.getProperty("config.resource", "application.test.conf")
Instead of Test plug in whatever config you have. If you don't explicitly pass a config.resource parameter it will use application.test.conf.

Build a VS2003 project from the command line without outputting warnings

Anyone know if it's possible to build a VS2003 project from the command line without showing any warnings? We've got a heap of VS2003 projects that get built by TSFBuild as part of our platform build and the warnings are just noise in the build log file.
I have looked at the parameters by running devenv.com /help and nothing there seems relevant. VS2010 has a build output verbosity setting but I couldn't find one for VS2003. I am also looking to see if it can be configured through the project file.
Seems like you're building your projects using MSBuild. If so, you can try suppress the warnings by setting the WarningLevel property as suggested here. Or you can choose the console logger to not show the warning and error summary, then output them to seperate files as provided here:
/consoleloggerparameters:parameters
NoSummary: Hides the error and warning summary displayed at the end
of a build.
/fileloggerparameters:
You can use up to ten file loggers by
following the parameter with a digit
identifying the logger. For example,
to generate separate log files for
warnings and errors, use -
/flp1:logfile=errors.txt;errorsonly
/flp2:logfile=warnings.txt;warningsonly