How to use environment variable in Poco:FileChannel "Path" property - poco-libraries

I'm using Poco::LoggingConfigurator library for logging, using Poco::XMLConfiguration to configure logging properties. I want to use an environment variable in path value of logging configuration xml file. How to do it in xml config file?
This is the xml configuration file i'm using now.
<logging>
<channels>
<logFileChannel>
<class>FileChannel</class>
<path>/logs/agent-xfs.log</path>
<rotation>1 M</rotation>
<archive>timestamp</archive>
<compress>true</compress>
<purgeCount>60</purgeCount>
</logFileChannel>
</channels>
<loggers>
<root>
<channel>logFileChannel</channel>
<level>debug</level>
</root>
</loggers>
I want to define path variable value using environment variable like follows,
${ENV_SAMPLE_VARAIBLE}/logs/agent-xfs.log

You can refer to environment variables using ${system.env.NAME}, e.g.:
<path>${system.env.LOGPATH}/agent-xfs.log</path>
In order for ${system.env.LOGPATH} to resolve you'll need to have a Poco::Util::LayeredConfiguration containing both a Poco::Util::SystemConfiguration and your Poco::Util::XMLConfiguration:
Poco::AutoPtr<Poco::Util::LayeredConfiguration> pConfig = new Poco::Util::LayeredConfiguration;
pConfig->add(new Poco::Util::SystemConfiguration, 100, false, false);
pConfig->add(new Poco::Util::XMLConfiguration(configFilePath.toString()), 0, false, false);
LoggingConfigurator loggingConfigurator; loggingConfigurator.configure(pConfig);
Note that Poco::Util::Application would do that automatically if you were using it to handle the configuration.

Related

How to pass a parameter from the Jupyter backend to a frontend extension

I currently have a value that is stored as an environment variable the environment where a jupyter server is running. I would like to somehow pass that value to a frontend extension. It does not have to read the environment variable in real time, I am fine with just using the value of the variable at startup. Is there a canonical way to pass parameters a frontend extension on startup? Would appreciate an examples of both setting the parameter from the backend and accessing it from the frontend.
[update]
I have posted a solution that works for nbextentions, but I can't seem to find the equivalent pattern for labextensions (typescript), any help there would be much appreciated.
I was able to do this by adding the following code to my jupter_notebook_config.py
from notebook.services.config import ConfigManager
cm = ConfigManager()
cm.update('notebook', {'variable_being_set': value})
Then I had the parameters defined in my extension in my main.js
// define default values for config parameters
var params = {
variable_being_set : 'default'
};
// to be called once config is loaded, this updates default config vals
// with the ones specified by the server's config file
var update_params = function() {
var config = Jupyter.notebook.config;
for (var key in params) {
if (config.data.hasOwnProperty(key) ){
params[key] = config.data[key];
}
}
};
I also have the parameters declared in my main.yaml
Parameters:
- name: variable_being_set
description: ...
input_type: text
default: `default_value`
This took some trial and error to find out because there is very little documentation on the ConfigManager class and none of it has an end-to-end example.

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

Symfony 3 Translations Custom Domain

I'm trying to add custom domain into the project.
I have regions.locale.yaml file.
I'm trying load it in twig:
{{'united.kingdom'|trans|raw}}
But this doesn't work.
I think it has to be somehow declared that this file exists.
I found this in documentation:
// ...
$translator->addLoader('xlf', new XliffFileLoader());
$translator->addResource('xlf', 'messages.fr.xlf', 'fr_FR');
$translator->addResource('xlf', 'admin.fr.xlf', 'fr_FR', 'admin');
$translator->addResource(
'xlf',
'navigation.fr.xlf',
'fr_FR',
'navigation'
);
But where should I put this to declare my regions.locale.yaml files globally?
Thanks
If you are using Symfony Standard, you don't have to declare your translation files, you just put them in app/Resources/translations.
The key is that when you want to translate using your custom domain, you just specify your domain, like this :
{{'united.kingdom'|trans({}, 'regions')|raw }}
or somewhere else in your code :
$translator->trans('united.kingdom', [], 'regions');

External environment variable as array

How to set external environment variable as array?
If I have environment variable
SYMFONY__NSQLOOKUPD__HOSTS=["localhost:4161"]
and in config.yml:
socloz_nsq:
lookupd_hosts: %nsqlookupd.hosts%
Then I got an error:
Invalid type for path "socloz_nsq.lookupd_hosts". Expected array, but got string
I've found solution. Here it is:
in config.yml add to the imports section:
imports:
- { resource: parameters.php }
then create parameters.php file at the same directory where config.yml exists, and look at the following example:
<?php
$nsqlookupdhosts = getenv('SYMFONY__NSQLOOKUPD__HOSTS');
$nsqdhosts = getenv('SYMFONY__NSQD__HOSTS');
$container->setParameter('nsqlookupd.hosts.parsed', explode(',', $nsqlookupdhosts));
$container->setParameter('nsqd.hosts.parsed', explode(',', $nsqdhosts));
use comma as delimiter in environment variable (you are not restricted to comma, use any)
SYMFONY__NSQLOOKUPD__HOSTS=localhost:4161,some.server:2222
You can use a built-in "json" environment variable processor to decode a JSON string into an array:
SYMFONY__NSQLOOKUPD__HOSTS='["localhost:4161"]'
$nsqlookupdhosts: '%env(json:SYMFONY__NSQLOOKUPD__HOSTS)%'

Meteor: Importing a JS file isn't working

I have created a JS file inside the lib folder which has a JSON Object assigned to a variable and i am trying to use that variable in the Client folder, in of the template helper function but i get error while running saying the variable isn't defined.
How to solve this ? How to use this variable in both Client and Server ?
deviceMap.js -> inside lib folder
var deviceMap = {
"123456": {
"name": "ABC",
"department": "dept1"
}
}
Template.tmp1.helpers({
console.log(deviceMap);
});
Thank you
Prior to meteor 1.3, the only way to share variables between files is through the global namespace.
Replace:
var deviceMap =
with:
deviceMap =
and your variable will be global instead of file scoped. You may also want to consider namespacing your variable like: DeviceMaps.departments or something.

Resources