-2


So, I have an application in PHP that register users and items and then I can "give" an item to a user, and what I want it to create a log file that register the 'life cycle' of an item. eg:
I create an item and give that item to the user 'Mike', a few weeks later the user 'Mike' give back that item bc the item broked, and I want all that to be on a log file.
Any tips? Thanks!

Missing No
  • 3
  • 1
  • 5
  • This is a very general design question and have no reall clear question. But basically you want a log file named after the item somehow and then append to it on operations. This will probably create a lot of files if your system is around for a long time and you do not do clean up. – Virre Oct 29 '18 at 14:08
  • 1
    The posted question does not appear to include [any attempt](https://idownvotedbecau.se/noattempt/) at all to solve the problem. StackOverflow expects you to [try to solve your own problem first](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users), as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific problem you're having in a [mcve]. For more information, please see [ask] and take the [tour]. – Blue Oct 29 '18 at 14:08
  • have a look here: https://logging.apache.org/log4php/ – Doğan Uçar Oct 29 '18 at 14:10
  • Maybe logging is not the right choice here. Perhaps a database with an appropriate relationship between users and items might work better – apokryfos Oct 29 '18 at 14:18
  • @apokryfos it has, user.id is the FK between items and users, but I want all the records to be saved on a log file – Missing No Oct 29 '18 at 14:23
  • If it's properly set-up then you can get the information you need using database queries. If you can't then you need to re-design it in such a way that it would allow you to do so. – apokryfos Oct 29 '18 at 14:24
  • @apokryfos using database querys? how?? – Missing No Oct 29 '18 at 14:25

2 Answers2

1
$fp = fopen('logfile.txt', 'a');
fwrite($fp, date("Your date format").'Item xy passed from User Mike to User Alice');
fclose($fp);

a indicates to open the file and point to the end (typical for log files). Then you just print a timestamp and write which Item was passed from which user to which user, and close the file again. Just execute this after your actual code.

Lithilion
  • 1,097
  • 2
  • 11
  • 26
  • But how do I store the old owner of the item? Because i would need something like `the item $item was givven to $name` and further `the item $item was returned by $name because $reason` – Missing No Dec 06 '18 at 10:24
1

For what it's worth MySQL provides the very efficient ARCHIVE storage engine, suitable for write-a-lot read-infrequently use patterns.

It's a good choice if you want your log data in the DBMS (backed up, etc).

It's also a good choice for log data when your web app runs on multiple servers: all the entries go to one place, and you don't have to wonder which machine a particular log entry lives on.

O. Jones
  • 103,626
  • 17
  • 118
  • 172