Silverstripe 4 error log - silverstripe-4

How can I log errors to file log in SilverStripe 4?
I mean all errors causing 'Internal server error' info from SS
In SilverStripe it was :
SS_Log::add_writer(new SS_LogFileWriter('/var/log/silverstripe/errors.log'), SS_Log::ERR);
Documentation says that I need to do something like:
SilverStripe\Core\Injector\Injector:
Psr\Log\LoggerInterface:
calls:
LogFileHandler: [ pushHandler, [ %$LogFileHandler ] ]
LogFileHandler:
class: Monolog\Handler\StreamHandler
constructor:
- "../silverstripe.log"
- "info"
I try this but cannot get this to work :(

Try to add to your .env file (https://docs.silverstripe.org/en/4/getting_started/environment_management/) such string:
SS_ERROR_LOG = "silverstripe.log"

To create a custom log try:
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
Then later:
$logger = new Logger("my_name");
$logger->pushHandler(new StreamHandler('./silverstripe-custom.log', Logger::INFO));
$logger->info('hi there');
You should find silverstripe-custom.log in the project root.

Related

How to control log level of deno/std/log module from command line?

for example, how to log out debug info Hello world for
import * as log from "https://deno.land/std#0.173.0/log/mod.ts";
// Simple default logger out of the box. You can customize it
// by overriding logger and handler named "default", or providing
// additional logger configurations. You can log any data type.
log.debug("Hello world");
log.info(123456);
log.warning(true);
log.error({ foo: "bar", fizz: "bazz" });
log.critical("500 Internal server error");
from https://deno.land/std#0.173.0/log/mod.ts
I tried deno run -A --log-level=DEBUG with no luck.
for example, how to log out debug info Hello world for...
Below is an example of how you can configure all levels of logging to the console at "DEBUG" and above.
The module at https://deno.land/std#0.174.0/log/mod.ts includes some example code that looks just like the lines in your question (on lines 97-153 in the file) — it is what I used as a basis for the code below.
so-75244033.ts:
import * as log from "https://deno.land/std#0.174.0/log/mod.ts";
// This could be read from an environment variable or parsed from a CLI argument:
const LOG_LEVEL = "DEBUG";
log.setup({
handlers: {
console: new log.handlers.ConsoleHandler(LOG_LEVEL),
},
loggers: {
default: {
level: LOG_LEVEL,
handlers: ["console"],
},
},
});
// Simple default logger out of the box. You can customize it
// by overriding logger and handler named "default", or providing
// additional logger configurations. You can log any data type.
log.debug("Hello world");
log.info(123456);
log.warning(true);
log.error({ foo: "bar", fizz: "bazz" });
log.critical("500 Internal server error");
In the terminal:
% deno --version
deno 1.30.0 (release, x86_64-apple-darwin)
v8 10.9.194.5
typescript 4.9.4
% deno run so-75244033.ts
DEBUG Hello world
INFO 123456
WARNING true
ERROR {"foo":"bar","fizz":"bazz"}
CRITICAL 500 Internal server error

symfony 3 console command list in controller

As I am not sure how to describe it, I didn't found any results in google or stack.
I would like to list all available console commands (which are callable by using the bin/console) with a Controller-Action so that I can forward a list of all commands to twig.
How can I realize this ?
Interesting question. You can of course just run the console command itself and capture the list of commands. Might actually be the best way.
However, there is a service called console.command_loader which has a method called getNames which does indeed return a list of command names. It implements CommandLoaderInterface.
Originally I tried to create an alias so it could be injected into an action method:
services:
Symfony\Component\Console\CommandLoader\CommandLoaderInterface:
alias: console.command_loader
But I kept getting console.command_loader not found which was puzzling since debug:container shows it. The service was tagged with container.no_preload which might have something to do with it. Not sure.
So I went and just defined the controller service:
services:
App\Controller\CommandController:
tags:
- 'controller.service_arguments'
arguments:
- '#console.command_loader'
And somewhat to my surprise it worked.
class CommandController extends AbstractController
{
public function __construct(private CommandLoaderInterface $cl)
{
}
#[Route('/commands', name: 'app_commands')]
public function commands(): Response
{
$names = $this->cl->getNames();
dump($names);
// I happen to have a command called app:init
$initCommand = $this->cl->get('app:init');
dump($initCommand->getDescription());
//return $this->render('default/index.html.twig', [
// 'controller_name' => 'DefaultController ' . 'Commands',
//]);
}
}
This was all done in Symfony 6. Did not happen to have a Symfony 3 app handy. Your first step would be to confirm that Symfony 3 also has the service with bin/console debug:container console.command_loader. If it does not have such a service then poke around a bit and see if it has something similar.

custom logging does not works when set in systemProperties

I want to change log configuration for a node for that I have written a custom xml file where I have changed some configuration related to some specific module and rolling policies and I am using command: java -Dlog4j.configurationFile=custom-log.xml -jar corda.jar
This works fine with my custom configuration, but when I set same configuration in systemProperties section of node.conf as:
systemProperties = {
-Dlog4j.configurationFile = custom-log.xml
}
It does not follow my custom logging configuration. Can you help me with this?
Instead of
systemProperties = {
-Dlog4j.configurationFile = custom-log.xml
}
pass it as this:
systemProperties = {
log4j.configurationFile = custom-log.xml
}
-D is automatically appended

Use pydrill storage_update() to create Apache drill storage

I am trying to create MySQL apache drill storage plugin using pydrill. It is throwing error:
RequestError: TransportError(400, 'Unrecognized field "type" (class org.apache.drill.exec.server.rest.PluginConfigWrapper), not marked as ignorable (2 known properties: "config", "name"])\n at [Source: org.glassfish.jersey.message.internal.EntityInputStream#1843f42f; line: 1, column: 138] (through reference chain: org.apache.drill.exec.server.rest.PluginConfigWrapper["type"])')
Here is my code:
drill = PyDrill(host='host',port='8047',user='xx')
configu = '{"type": "jdbc","driver": "com.mysql.jdbc.Driver","url": "jdbc:mysql://host:3306","username": "xx","password": "xx",enabled:true}'
drill.storage_update('MySQL1',configu)
Any help is highly appreciated!
I found out the solution. We need to pass the storage name as a parameter, and as a json 'key':'value' in the config parameter.
Here is the corrected code:
configu={'config': {'driver': 'com.mysql.jdbc.Driver','enabled': True,'password': 'xyz','type': 'jdbc','url': 'jdbc:mysql://host:3306','username': 'xx'},'name':'xxx'}
drill.storage_update('xxx',config=configu)
And Bingo! It worked!

Artifactory quick search not filtering by repo

I am using Artifactory 4.8.0 (OSS)
I have deployed artifacts to 2 repos: libs-devel and libs-release-candidates.
When I execute
$ curl -u denham:password -X GET https://artifactory.server/artifactory/api/search/artifact?name=MyPackage&repos=libs-devel
The response I receive is:
"results" : [ {
"uri" : "https://artifactory.server/artifactory/api/storage/libs-devel/com/acme/MyPackage/17.10.1-SNAPSHOT/MyPackage-17.10.1-20170908.092803-1.pom"
}, {
"uri" : "https://artifactory.server/artifactory/api/storage/libs-devel/com/acme/MyPackage/17.10.1-SNAPSHOT/MyPackage-17.10.1-20170908.092803-1.war"
}, {
"uri" : "https://artifactory.server/artifactory/api/storage/libs-release-candidates/com/acme/MyPackage/17.10.1-24/MyPackage-17.10.1-24.pom"
}, {
"uri" : "https://artifactory.server/artifactory/api/storage/libs-release-candidates/com/acme/MyPackage/17.10.1-24/MyPackage-17.10.1-24.war"
}, {
"uri" : "https://artifactory.server/artifactory/api/storage/libs-devel/com/acme/MyPackage/17.9.3-SNAPSHOT/MyPackage-17.9.3-20170907.105908-1.pom"
}, {
"uri" : "https://artifactory.server/artifactory/api/storage/libs-devel/com/acme/MyPackage/17.9.3-SNAPSHOT/MyPackage-17.9.3-20170907.105908-1.war"
} ]
}
I would expect that the results would be limited to the the libs-devel repo, as specified in the url.
Have I done something wrong? Is this a bug?
Here's the API reference (for version 4) that I followed:
https://www.jfrog.com/confluence/display/RTF4X/Artifactory+REST+API#ArtifactoryRESTAPI-ArtifactSearch(QuickSearch)
Thanks in advance.
Yes. This is correct.
You will be able to limit the search query to specific repositories by adding the 'repos' parameter on this rest call.
We (JFrog) are not familiar with a bug on this subject and it is working on our side (Artifactory OSS - same version: 4.8.0).
We will be interested to know if the same is working for you using the UI quick search.
If using curl, the full URL needs to be encapsulated in quotes. Otherwise the & is left off the request.
I tried using Postman and it works as expected.
Bested by quote marks. :-(

Resources