engine.ShowError not available anymore? #649

Open
opened 2017-07-22 15:09:17 +00:00 by pjmuller · 7 comments
pjmuller commented 2017-07-22 15:09:17 +00:00 (Migrated from github.com)

In the documentation (https://github.com/coscms/xorm/blob/master/docs/QuickStart.md > Section 1: Create ORM Engine > 1.Logs)

I saw that there was/is an engine.ShowError = true. However the ShowError is not an attribute / method anymore. Also I don't find it anywhere in the code.

Did this dissapear? If so, why? And could you bring it back?

Other than that, really enjoying the library. Big kudos :)!

In the documentation (https://github.com/coscms/xorm/blob/master/docs/QuickStart.md > Section 1: Create ORM Engine > 1.Logs) I saw that there was/is an `engine.ShowError = true`. However the ShowError is not an attribute / method anymore. Also I don't find it anywhere in the code. Did this dissapear? If so, why? And could you bring it back? Other than that, really enjoying the library. Big kudos :)!

Yes, we have upgrade the usage. This is not compitable with old version. The document is too old that I will update it later. Now you have to engine.SetLogger() and set the log level. You can use your favorite logger to do that since core.ILogger is an interface.

Yes, we have upgrade the usage. This is not compitable with old version. The document is too old that I will update it later. Now you have to `engine.SetLogger()` and set the log level. You can use your favorite logger to do that since `core.ILogger` is an interface.
pjmuller commented 2017-07-23 07:45:06 +00:00 (Migrated from github.com)

Hi @lunny , thanks for the fast answer!

I just tried engine.SetLogger(xorm.NewSimpleLogger3(os.Stdout, "[db]", log.Ldate|log.Lmicroseconds|log.LUTC, core.LOG_ERR))

However this does not show errors for queries that failed (e.g. when incorrect column name). How can I solve this?

Hi @lunny , thanks for the fast answer! I just tried `engine.SetLogger(xorm.NewSimpleLogger3(os.Stdout, "[db]", log.Ldate|log.Lmicroseconds|log.LUTC, core.LOG_ERR))` However this does not show errors for queries that failed (e.g. when incorrect column name). How can I solve this?

Engine.ShowSQL(true) will record SQL into logger as info log level

Engine.ShowSQL(true) will record SQL into logger as info log level
pjmuller commented 2017-07-23 08:12:11 +00:00 (Migrated from github.com)

Hi Lunny, it seems we are talking about something different.

I want to show the Postgresql errors as they occur without having to _, err := db.Insert(), fmt.Println(err) for example.

I played a bit with Engine.ShowSQL(true) and with different core.loglevels . From the moment I put core.LOG_INFO I see all the queries being executed but still no messages for failed queries.

So the ideal scenario for me is.

  • only show SQL for queries that failed
  • show the Postgresql error message as well

Can I achieve that with the logger? and if not, how do you suggest to go about?

Hi Lunny, it seems we are talking about something different. I want to show the Postgresql errors as they occur without having to `_, err := db.Insert()`, `fmt.Println(err)` for example. I played a bit with `Engine.ShowSQL(true)` and with different `core.loglevels` . From the moment I put `core.LOG_INFO` I see all the queries being executed but still no messages for failed queries. So the ideal scenario for me is. - only show SQL for queries that failed - show the Postgresql error message as well Can I achieve that with the logger? and if not, how do you suggest to go about?

@pjmuller if Postgresql return en error, xorm will return the error via err on _, err := db.Insert() so you have to show the error yourself.

You can show the last SQL via session.LastSQL() after you execute Find, Insert and etc.

@pjmuller if Postgresql return en error, xorm will return the error via err on `_, err := db.Insert()` so you have to show the error yourself. You can show the last SQL via `session.LastSQL()` after you execute `Find, Insert` and etc.
pjmuller commented 2017-07-24 06:57:52 +00:00 (Migrated from github.com)

Hi @lunny , thanks for the session.LastSQL() info.

Do you see a way to hook into that error? So that I don't have to do always do _, err := ...

Writing a wrapper is hard without forking the project (as I can't extend the Engine type). Would loved to have solved this with a logger or alike. Any ideas?

Hi @lunny , thanks for the `session.LastSQL()` info. Do you see a way to hook into that error? So that I don't have to do always do `_, err := ...` Writing a wrapper is hard without forking the project (as I can't extend the Engine type). Would loved to have solved this with a logger or alike. Any ideas?

I'm afraid there is no the hook to do that. And currently I have no idea about how to add a hook satisfied with this.

I'm afraid there is no the hook to do that. And currently I have no idea about how to add a hook satisfied with this.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#649
No description provided.