I have problem log exception only message is logged.
NLog config:
<target name="logfile"
xsi:type="File"
fileName="log.txt"
layout="${longdate} | ${machinename} | ${processid} | ${processname} | ${level} | ${logger} | |${message} | ${exception:format=tostring}" />
<logger name="*"
minlevel="Info"
writeTo="logfile" />
Usage:
private static Logger _logger = LogManager.GetCurrentClassLogger();
_logger.Error("my message", new Exception("my exception"));
Log output:
2014-04-24 18:17:29.0841 | PC_NAME | 6464 | APP_NAME.vshost | Error | AppName.ViewModel | my message |
Exception is ignore.
I found some thread but for me not work.
Nlog is using sepecial methods for logging exceptions which are using the <loglevel>Exception naming schema.
So in your case you need to use the ErrorException method in order to your exceptions get logged correctly:
private static Logger _logger = LogManager.GetCurrentClassLogger();
_logger.ErrorException("my message", new Exception("my exception"));
Actually, void Error(string message, Exception exception); is obsolete
You can use ILogger.Error(Exception, string) method like below
catch (Exception e)
{
Log.Error(e, "it happens");
}
and a little bit modified layout with ${onexception}. This will check is there an exception to be logged
<target name="logfile"
xsi:type="File"
fileName="log.txt"
layout="${longdate} | ${machinename} | ${processid} | ${processname} | ${level} | ${logger} | |${message} ${onexception:| ${exception:format=tostring}}" />
/>
Related
I am trying to write tests for an express API that uses Axios and is connected to a mySQL database. I am getting the following error when I run my tests in Jest:
A worker process has failed to exit gracefully and has been force exited. This is
likely caused by tests leaking due to improper teardown. Try running with --
detectOpenHandles to find leaks. Active timers can also cause this, ensure that
.unref() was called on them.
After running detectOpenHandles, I get the following:
Jest has detected the following 3 open handles potentially keeping Jest from exiting:
● TCPWRAP
15 |
16 |
> 17 | const connection = mysql.createConnection(process.env.MYSQL_CONNECTION)
| ^
18 |
19 | /**
20 | * #swagger
at new Connection (node_modules/mysql2/lib/connection.js:45:27)
at Object.createConnection (node_modules/mysql2/index.js:10:10)
at Object.<anonymous> (src/users/router.js:17:26)
at Object.<anonymous> (src/index.js:9:25)
at Object.<anonymous> (src/server.js:1:13)
at Object.<anonymous> (__tests__/app.test.js:3:13)
● TCPSERVERWRAP
3 |
4 |
> 5 | app.listen(serverPort, () =>
| ^
6 | console.log(`API Server listening on port ${serverPort}`)
7 | );
8 |
at Function.listen (node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (src/server.js:5:5)
at Object.<anonymous> (__tests__/app.test.js:3:13)
● TLSWRAP
16 | const getMgmtApiJwt = async () => {
17 | try {
> 18 | const resp = await axios(newRequest);
| ^
19 | return resp.data
20 | } catch (e) {
21 | console.log("did not work");
at RedirectableRequest.Object.<anonymous>.RedirectableRequest._performRequest (node_modules/follow-redirects/index.js:279:24)
at new RedirectableRequest (node_modules/follow-redirects/index.js:61:8)
at Object.request (node_modules/follow-redirects/index.js:487:14)
at dispatchHttpRequest (node_modules/axios/lib/adapters/http.js:202:25)
at httpAdapter (node_modules/axios/lib/adapters/http.js:46:10)
at dispatchRequest (node_modules/axios/lib/core/dispatchRequest.js:53:10)
at Axios.request (node_modules/axios/lib/core/Axios.js:108:15)
at axios (node_modules/axios/lib/helpers/bind.js:9:15)
at getMgmtApiJwt (src/users/controller.js:18:24)
at Object.<anonymous> (__tests__/app.test.js:182:24)
What can I try next?
Implement a global tear down setup. That should fix this issue.
Take a look at Fiehra's answer here: jest and mongoose - jest has detected opened handles
I am using couchbase image with base version 4.6.3 in docker-compose . But I am getting the below error while launching docker-compose up : -
couchbase_1 | SUCCESS: init/edit couchbase.docker
couchbase_1 | SUCCESS: set hostname for couchbase.docker
couchbase_1 | SUCCESS: bucket-create
couchbase_1 | ....2017-11-13 09:57:06,301: w0 Fail to read json file with error:No JSON object could be decoded
couchbase_1 | .
couchbase_1 | bucket: ., msgs transferred...
couchbase_1 | : total | last | per sec
couchbase_1 | byte : 251515 | 251515 | 3987233.9
couchbase_1 | done
couchbase_1 | /entrypoint.sh couchbase-server
Making the Json file to compact single line resolved the error.
We've discovered a bug in the IoT Agent Ultralight.
If we try to send a measure to a non existing device, we'll get a 404 - DEVICE_NOT_FOUND error but at the same time a device without any attribute will be created in IoTA's and Orion CB's database.
When I say a device without any attribute I refer to the following:
{
"device_id": "test",
"service": "MyService",
"service_path": "/MyServicePath",
"entity_name": "MyEntity:test",
"entity_type": "MyEntity",
"attributes": [],
"lazy": [],
"commands": [],
"static_attributes": []
}
This is a very important bug, because it's really simple to create as many devices as someone wants and that could eat our database space.
Does someone know how to solve it?
Which version of IotAgent-ul and external components, I mean, (Fiware OCB and MongoDB) are you using? It's highly recommend to use the latest one.
It's a good way to run OCB and MongoDB using docker images
Could you provided us your commands/code that you used to send a meassure?
From my self, I tested it and it works great:
Curl commands used to send a meassure:
#!/usr/local/bin
mosquitto_pub -t /TEF/sensor03/attrs -m 't|45|c|extreme'
Response from IotAgent-ul:
{"op":"IOTAUL.Executable","time":"2018-09-21T09:59:17.906Z","lvl":"INFO","msg":"Ultralight 2.0 IoT Agent started"}
time=2018-09-21T09:59:32.679Z | lvl=DEBUG | corr=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | trans=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=n/a | subsrv=n/a | msg=Looking for device with filter [{"id":"sensor03"}]. | comp=IoTAgent
Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
time=2018-09-21T09:59:32.717Z | lvl=ERROR | corr=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | trans=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | op=IOTAUL.IoTUtils | srv=n/a | subsrv=n/a | msg=MEASURES-001: Couldn't find device data for APIKey [TEF] and DeviceId[sensor03] | comp=IoTAgent
time=2018-09-21T09:59:32.717Z | lvl=ERROR | corr=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | trans=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | op=IOTAUL.Common.Binding | srv=n/a | subsrv=n/a | msg=MEASURES-005: Error before processing device measures [/TEF/sensor03/attrs] | comp=IoTAgent
time=2018-09-21T10:09:51.484Z | lvl=DEBUG | corr=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | trans=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=n/a | subsrv=n/a | msg=Looking for device with filter [{"id":"sensor03"}]. | comp=IoTAgent
time=2018-09-21T10:09:51.504Z | lvl=ERROR | corr=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | trans=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | op=IOTAUL.IoTUtils | srv=n/a | subsrv=n/a | msg=MEASURES-001: Couldn't find device data for APIKey [TEF] and DeviceId[sensor03] | comp=IoTAgent
time=2018-09-21T10:09:51.509Z | lvl=ERROR | corr=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | trans=dbbcd94d-50fc-4062-a05b-bccfa76c52c8 | op=IOTAUL.Common.Binding | srv=n/a | subsrv=n/a | msg=MEASURES-005: Error before processing device measures [/TEF/sensor03/attrs] | comp=IoTAgent
Show data from MongoDB
root#727724bdd3d9:/# mongo --shell
MongoDB shell version: 3.2.21
connecting to: test
type "help" for help
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> show dbs
iotagentul 0.000GB
local 0.000GB
orion 0.000GB
It seems to me that you have something wrong about your config set up. Please provide us all the points before comment and for a nice follow up, could you open it in the Github site ? IotAgent-UL Take up there
Thanks,
Fernando Méndez - Research Junior Software Engineer
After solving my initial properties-local.xml issue, I have moved on to another problem. I initially had a naming context error that I resolved by changing the value of oxf.fr.persistence.provider.*.*.* to be db matching my resource definition for JBoss.
Now, when saving a form definition I receive an error dialogue with the message.
There was an error communicating with the database.
Please contact the application administrator.
When I check the server.log I noticed that the first exception occurred after clicking continue after inputting the new form name, title and description.
The exception is this:
21:41:26,312 ERROR [org.orbeon.oxf.controller.PageFlowControllerProcessor] (http--127.0.0.1-8080-8) error caught {controller: "oxf:/apps/fr/page-flow.xml", method: "GET", path: "/fr/service/persistence/crud/orbeon/library/form/form.xhtml"}
21:41:26,406 ERROR [org.orbeon.oxf.controller.PageFlowControllerProcessor] (http--127.0.0.1-8080-8)
+----------------------------------------------------------------------------------------------------------------------+
|An Error has Occurred |
|----------------------------------------------------------------------------------------------------------------------|
|org.orbeon.oxf.common.ValidationException: line 18, column 47 of oxf:/apps/fr/persistence/proxy.xpl (executing process|
|----------------------------------------------------------------------------------------------------------------------|
|Application Call Stack |
|----------------------------------------------------------------------------------------------------------------------|
|oxf:/apps/fr/page-flow.xml |reading page model data output| 18|
|······················································································································|
|element=<service path="/fr/service/persistence/.*" model="persistence/proxy.xpl"/> |
|model =persistence/proxy.xpl |
|----------------------------------------------------------------------------------------------------------------------|
|oxf:/apps/fr/persistence/proxy.xpl |executing processor | 18|
|······················································································································|
|element=<p:processor name="fr:persistence-proxy"/> |
|name ={http://orbeon.org/oxf/xml/form-runner}persistence-proxy |
|----------------------------------------------------------------------------------------------------------------------|
|----------------------------------------------------------------------------------------------------------------------|
|Exception: java.lang.NullPointerException |
I'm assuming my properties-local.xml needs some work. Here are the contents:
<properties xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<property as="xs:string" name="oxf.fr.persistence.provider.*.*.*" value="db"/>
<property as="xs:string" name="oxf.fr.persistence.mysql.datasource" value="db"/>
</properties>
I had the same error without the second property.
I'm blocked on this problem for many hours and I don't understand the problem as it works fine with another entity of my project.
I created a Java EE project with Glassfish 4, JPA 2 and EJB 3 in Eclipse IDE.
I'm using a mysql database for storing.
I created a entity bean named Company and a DAO to manage it. I did all it needs to work and it works well.
The problem is that I did exactly the same thing for another entity bean, called Newsletter, but this one doesn't work.
Java throws an EJBException, telling me that the abstract schema is unknown, but it exists in the DB.
The tables company and newsletter are in the same db, so I used the same persistence unit for both of them.
Some questions I found on Google or here are solved by adding the class to the persitence-unit and I did it, but it still throws me an exception.
Here is my NEWSLETTER table:
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| idNewsletter | int(11) | NO | PRI | NULL | auto_increment |
| firstname | varchar(100) | NO | | NULL | |
| lastname | varchar(100) | NO | | NULL | |
| email | varchar(255) | NO | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
My bean Newsletter:
#Entity
public class Newsletter {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idNewsletter;
#Column(name="firstname")
private String firstname;
#Column(name="lastname")
private String lastname;
#Column(name="email")
private String email;
}
Here is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="2lifedb_PU" transaction-type="JTA">
<jta-data-source>jdbc/bonecp_resource</jta-data-source>
<class>com.twolife.beans.User</class>
<class>com.twolife.beans.Company</class>
<class>com.twolife.beans.Office</class>
<class>com.twolife.beans.BankDetails</class>
<class>com.twolife.beans.Logo</class>
<class>com.twolife.beans.Newsletter</class>
<properties>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
And the DAO class:
#Stateless
public class DAONewsletter {
private static final String SQL_SELECT_NEWSLETTER = "SELECT n FROM NEWSLETTER n WHERE n.email = :email";
#PersistenceContext(unitName="2lifedb_PU")
private EntityManager em;
public void create(Newsletter newsletter) throws DAOException {
try {
em.persist(newsletter);
} catch (Exception e) {
throw new DAOException(e);
}
}
public Newsletter find(String email) throws DAOException {
Newsletter newsletter = new Newsletter();
Query query = em.createQuery(SQL_SELECT_NEWSLETTER);
query.setParameter("email", email);
try {
newsletter = (Newsletter) query.getSingleResult();
} catch (NoResultException e) {
return null;
} catch (Exception e) {
throw new DAOException(e);
}
return newsletter;
}
}
And finally, here is the stacktrace of my exception:
Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [SELECT n FROM NEWSLETTER n WHERE n.email = :email].
[14, 24] The abstract schema type 'NEWSLETTER' is unknown.
[33, 40] The state field path 'n.email' cannot be resolved to a valid type.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1585)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:456)
at com.twolife.dao.DAONewsletter.find(DAONewsletter.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
... 36 more
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [SELECT n FROM NEWSLETTER n WHERE n.email = :email].
[14, 24] The abstract schema type 'NEWSLETTER' is unknown.
[33, 40] The state field path 'n.email' cannot be resolved to a valid type.
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:155)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:347)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:278)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:163)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:142)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:116)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:102)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:86)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1583)
... 60 more
If anoyone get an idea, that would be really helpful!
And sorry for some english mistakes, it is not my mother language...
em.createQuery() expects a JPQL query, not a SQL query. SQL and JPQL are not the same language. SQL works with tables and columns. JPQL works with entities, fields/properties and associations. NEVER with table and column names. The syntax is similar, but different.
Your entity is named Newsletter, but your query uses NEWSLETTER. Class names are case sensitive.
I had the same issue in wildfly 10.0 with eclipselink 2.6.
I solved adding the following system property to standalone.xml file
<?xml version='1.0' encoding='UTF-8'?>
<server xmlns="urn:jboss:domain:4.2">
<system-properties>
<property name="eclipselink.archive.factory" value="org.jipijapa.eclipselink.JBossArchiveFactoryImpl"/>
</system-properties>
...
</server>